Git Everything--利用Git进行机器人程序版本管理

本文介绍了git作为一种流行的分布式版本控制系统在工控领域的应用,包括安装步骤、基本操作(如初始化仓库、保存版本、查看版本和回退)以及git的核心功能。

git 是目前最流行的分布式版本控制系统,对于大部分程序员来说是最不陌生了,但对于工控领域可能不是很熟悉,但其强大的功能同样可以适用于工控领域程序版本控制,那么什么是git,如何方便的用git来控制版本呢?

在这里插入图片描述

什么是版本控制,git如何实现版本控制的?

在工控领域中日常工作过程中,很多工程师工作可能专注于某个专门的领域,在此行业中可能保存了专门针对某些工艺的样板程序,但在做每个项目时客户的工艺要求不尽相同,同时在客户对某些工艺提出特殊要求时,需要不断的调整程序的结构。但是当实际运行时客户发现提出的功能不好用需要返回到原来的功能时,我们需要怎么办呢?
简单的方法那当然是在实现更改前多备份程序,如果真的出现回退时直接将原来的程序导入到设备中就行了。这也是我们经常使用的方法
但是如果客户只是要某个功能部分恢复,应该怎么办,细心的工程师可能记得每个备份更新的内容,但如果过了很多时间再回来看呢,程序过于复杂要用哪个备份呢,如何方便的查看各个备份的更新内容呢?

git这时就大有作为了,其可以将你备份中的程序进行分析并发现其中的不同,同时在你每次备份后可以添加当前备份增加的功能及优化的内容,使用git几大优点如下:
1、不必每次备份专门为每个版本生成一个文件夹了,只需要一个文件夹就可以管理并且节省空间
2、可以查看每次提交的版本及版本更新的内容
3、可以方便的查看当前版本的文件与回退版本之间的差异,同时回退到每个版本,并查看当前版本的内容
4、更厉害的地方是可以几个同事一起开发某个功能,并可以实时更新
5、最牛逼的是git是完全免费的,如果你想在全球最大的开源网站github提交代码,那么你肯定需要了解git的

那么git如何实现这些功能的呢

didi@MacBook-Pro-5 gen4_production_test % git branch * dev-ota-merge-0903 master didi@MacBook-Pro-5 gen4_production_test % git remote add origin https://git.xiaojukeji.com/voyager-test-group/product-test/gen4_production_test.git error: remote origin already exists. didi@MacBook-Pro-5 gen4_production_test % git push -u origin HEAD:dev_ota_test To git.xiaojukeji.com:voyager-test-group/product-test/gen4_production_test.git ! [rejected] HEAD -> dev_ota_test (fetch first) error: failed to push some refs to 'git.xiaojukeji.com:voyager-test-group/product-test/gen4_production_test.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. didi@MacBook-Pro-5 gen4_production_test % git pull origin dev_ota_test remote: Enumerating objects: 196, done. remote: Counting objects: 100% (53/53), done. remote: Compressing objects: 100% (23/23), done. remote: Total 196 (delta 39), reused 41 (delta 30), pack-reused 143 Receiving objects: 100% (196/196), 87.48 KiB | 914.00 KiB/s, done. Resolving deltas: 100% (125/125), completed with 12 local objects. From git.xiaojukeji.com:voyager-test-group/product-test/gen4_production_test * branch dev_ota_test -> FETCH_HEAD * [new branch] dev_ota_test -> origin/dev_ota_test hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches. didi@MacBook-Pro-5 gen4_production_test % git pull origin dev_ota_test --rebase error: cannot pull with rebase: You have unstaged changes. error: please commit or stash them. didi@MacBook-Pro-5 gen4_production_test % git commit On branch dev-ota-merge-0903 Your branch is ahead of 'origin/dev-ota-merge-0903' by 5 commits. (use "git push" to publish your local commits) Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: common_lib/web_lib/api_generate_ota_task.py no changes added to commit (use "git add" and/or "git commit -a") didi@MacBook-Pro-5 gen4_production_test % git add . didi@MacBook-Pro-5 gen4_production_test % git pull origin dev_ota_test --rebase error: cannot pull with rebase: Your index contains uncommitted changes. error: please commit or stash them. didi@MacBook-Pro-5 gen4_production_test % git commit -a Aborting commit due to empty commit message. didi@MacBook-Pro-5 gen4_production_test % git pull origin dev_ota_test --no-rebase From git.xiaojukeji.com:voyager-test-group/product-test/gen4_production_test * branch dev_ota_test -> FETCH_HEAD error: Your local changes to the following files would be overwritten by merge: common_lib/web_lib/api_generate_ota_task.py <stdin>:10: trailing whitespace. task_url, <stdin>:19: trailing whitespace. task_url, warning: 2 lines add whitespace errors. Merge with strategy ort failed. didi@MacBook-Pro-5 gen4_production_test % git add common_lib/web_lib/api_generate_ota_task.py didi@MacBook-Pro-5 gen4_production_test % git commit -m "feat: 添加 OTA 任务生成接口调用" [dev-ota-merge-0903 78aa496] feat: 添加 OTA 任务生成接口调用 1 file changed, 2 insertions(+), 2 deletions(-) didi@MacBook-Pro-5 gen4_production_test % git pull origin dev_ota_test --no-rebase From git.xiaojukeji.com:voyager-test-group/product-test/gen4_production_test * branch dev_ota_test -> FETCH_HEAD Auto-merging cases/ota_test/test_general_ota.py CONFLICT (content): Merge conflict in cases/ota_test/test_general_ota.py Auto-merging common_lib/web_lib/api_generate_ota_task.py CONFLICT (content): Merge conflict in common_lib/web_lib/api_generate_ota_task.py Automatic merge failed; fix conflicts and then commit the result. didi@MacBook-Pro-5 gen4_production_test % git pull origin dev_ota_test --no-rebase From git.xiaojukeji.com:voyager-test-group/product-test/gen4_production_test * branch dev_ota_test -> FETCH_HEAD Already up to date. didi@MacBook-Pro-5 gen4_production_test % git branch * dev-ota-merge-0903 master didi@MacBook-Pro-5 gen4_production_test % git push To git.xiaojukeji.com:voyager-test-group/product-test/gen4_production_test.git ! [rejected] dev-ota-merge-0903 -> dev-ota-merge-0903 (fetch first) error: failed to push some refs to 'git.xiaojukeji.com:voyager-test-group/product-test/gen4_production_test.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. didi@MacBook-Pro-5 gen4_production_test % git branch * dev-ota-merge-0903 master didi@MacBook-Pro-5 gen4_production_test % git switch dev_ota_test branch 'dev_ota_test' set up to track 'origin/dev_ota_test'. Switched to a new branch 'dev_ota_test' didi@MacBook-Pro-5 gen4_production_test % git branch dev-ota-merge-0903 * dev_ota_test master didi@MacBook-Pro-5 gen4_production_test % git push -u origin dev_ota_test branch 'dev_ota_test' set up to track 'origin/dev_ota_test'. Everything up-to-date didi@MacBook-Pro-5 gen4_production_test % git branch dev-ota-merge-0903 * dev_ota_test master didi@MacBook-Pro-5 gen4_production_test % git add . didi@MacBook-Pro-5 gen4_production_test % git commit -m "提交机器人通知优化以及报文录制等" On branch dev_ota_test Your branch is up to date with 'origin/dev_ota_test'. nothing to commit, working tree clean didi@MacBook-Pro-5 gen4_production_test % git push Everything up-to-date didi@MacBook-Pro-5 gen4_production_test % git branch dev-ota-merge-0903 * dev_ota_test master didi@MacBook-Pro-5 gen4_production_test % git revert -m 1 HEAD [dev_ota_test 1564867] Revert "增加日志打印" 2 files changed, 1 insertion(+), 2 deletions(-) didi@MacBook-Pro-5 gen4_production_test % git log --oneline 1564867 (HEAD -> dev_ota_test) Revert "增加日志打印" a44efa5 (origin/dev_ota_test) 增加日志打印 501b72f 优化OTA前的磁盘空间清理 e5f7c7f voyager OTA前重启voy-ota,无需重启ACU df4c8a2 更新80101树莓派ip f0d3d5b voyager OTA前重启ACU 63f462d fix bug, 去掉注释,否则mdhil读不到version变量 09cceed Merge branch 'master' into dev-add_region_switch f53290a 解决空格引起的版本下载失败问题 a3d21f8 调整代码到lib dc7239f 增加改region代码 03a802a Merge branch 'master' into dev-add_region_switch b064d42 调试issue流程 e930019 切region自动化 097bfdd 服务器ip地址变更 b26a282 安装包文件增加匹配编译平台 bc1ee2a 调整升级方式为voy-ota-from-gift : a44efa5 (origin/dev_ota_test) 增加日志打印 501b72f 优化OTA前的磁盘空间清理 e5f7c7f voyager OTA前重启voy-ota,无需重启ACU df4c8a2 更新80101树莓派ip f0d3d5b voyager OTA前重启ACU 63f462d fix bug, 去掉注释,否则mdhil读不到version变量 09cceed Merge branch 'master' into dev-add_region_switch f53290a 解决空格引起的版本下载失败问题 a3d21f8 调整代码到lib dc7239f 增加改region代码 03a802a Merge branch 'master' into dev-add_region_switch b064d42 调试issue流程 e930019 切region自动化 097bfdd 服务器ip地址变更 b26a282 安装包文件增加匹配编译平台 bc1ee2a 调整升级方式为voy-ota-from-gift : a44efa5 (origin/dev_ota_test) 增加日志打印 501b72f 优化OTA前的磁盘空间清理 e5f7c7f voyager OTA前重启voy-ota,无需重启ACU df4c8a2 更新80101树莓派ip f0d3d5b voyager OTA前重启ACU 63f462d fix bug, 去掉注释,否则mdhil读不到version变量 09cceed Merge branch 'master' into dev-add_region_switch f53290a 解决空格引起的版本下载失败问题 a3d21f8 调整代码到lib dc7239f 增加改region代码 03a802a Merge branch 'master' into dev-add_region_switch b064d42 调试issue流程 e930019 切region自动化 097bfdd 服务器ip地址变更 b26a282 安装包文件增加匹配编译平台 bc1ee2a 调整升级方式为voy-ota-from-gift 9c086b3 kill-onboard-teleassis 413559e is_perf_test 立即落盘 2e55884 Change 80101 raspberry ip 2f6ca8a fenggaofeng:替换 apt install方式为 voy-ota-from-gift 4e13464 fenggaofeng:重启x86方式兼容A样和B样以及C样,不再需要单独切分支进行测试 c8526f6 Merge branch 'master' of git.xiaojukeji.com:voyager-test-group/product-test/gen4_production_test into dev_gen4_b_sp _reboot f601c35 fenggaofeng:lite_hil 碰撞节点增加perf flag,rtm、semantic、e2e增加启动动作。 bb9cf28 Merge branch 'master' of git.xiaojukeji.com:voyager-test-group/product-test/gen4_production_test into dev_gen4_b_sp: dc7239f 增加改region代码 03a802a Merge branch 'master' into dev-add_region_switch b064d42 调试issue流程 e930019 切region自动化 097bfdd 服务器ip地址变更 b26a282 安装包文件增加匹配编译平台 bc1ee2a 调整升级方式为voy-ota-from-gift 9c086b3 kill-onboard-teleassis 413559e is_perf_test 立即落盘 2e55884 Change 80101 raspberry ip 2f6ca8a fenggaofeng:替换 apt install方式为 voy-ota-from-gift 4e13464 fenggaofeng:重启x86方式兼容A样和B样以及C样,不再需要单独切分支进行测试 c8526f6 Merge branch 'master' of git.xiaojukeji.com:voyager-test-group/product-test/gen4_production_test into dev_gen4_b_sp_reboot f601c35 fenggaofeng:lite_hil 碰撞节点增加perf flag,rtm、semantic、e2e增加启动动作。 bb9cf28 Merge branch 'master' of git.xiaojukeji.com:voyager-test-group/product-test/gen4_production_test into dev_gen4_b_sp didi@MacBook-Pro-5 gen4_production_test % 帮我看一下是哪步将代码提交了我合并冲突之后原来的代码不见了想退回到原来的代码上
最新发布
11-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值