Flutter开发App的未来及其在各行业的应用潜力分析
599
2022-10-09
Git冲突处理
Git冲突很常见。本质是两个分支之间都提交了相同的东西,如:
同时修改了同一份文件创建了相同的文件
解决冲突的办法:
手动合并两个文件,各自再提交,然后再进行合并选择保留其中一份文件,删除掉另一份
同时修改了同一份文件引起的冲突及其解决方法例子:
# 切换到master分支~/Desktop/MyApp$ git checkout statusOn branch masternothing to commit, working tree clean~/Desktop/MyApp$ lsapp H.txt# 创建两个分支~/Desktop/MyApp$ git branch tt01~/Desktop/MyApp$ git branch tt02# 修改tt01分支的H.txt文件~/Desktop/MyApp$ git checkout tt01Switched to branch 'tt01'~/Desktop/MyApp$ lsapp H.txt~/Desktop/MyApp$ echo hello > H.txt~/Desktop/MyApp$ git add H.txt~/Desktop/MyApp$ git commit H.txt -m "init H.txt"~/Desktop/MyApp$ cat H.txthello# 修改tt02分支的H.txt文件~/Desktop/MyApp$ git checkout tt02~/Desktop/MyApp$ lsapp H.txt~/Desktop/MyApp$ echo hi > H.txt~/Desktop/MyApp$ git add H.txt~/Desktop/MyApp$ git commit H.txt -m "init H.txt"~/Desktop/MyApp$ cat H.txthi# 将分支tt02合并到分支tt01~/Desktop/MyApp$ git checkout tt01Switched to branch 'tt01'# 合并tt02到tt01过程中,出现冲突~/Desktop/MyApp$ git merge tt02Auto-merging H.txtCONFLICT (content): Merge conflict in H.txtAutomatic merge failed; fix conflicts and then commit the result.~/Desktop/MyApp$ cat H.txt<<<<<<< HEADhello=======hi>>>>>>> tt02~/Desktop/MyApp$ git statusOn branch tt01You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge)Unmerged paths: (use "git add
创建了相同的文件引起的冲突及其解决方法例子:
# 切换到master分支~/Desktop/MyApp$ git checkout masterSwitched to branch 'master'# 创建分支test01 、test02~/Desktop/MyApp$ git branch test01~/Desktop/MyApp$ git branch test02# 在test01分支创建一个test.txt文件~/Desktop/MyApp$ git checkout test01Switched to branch 'test01'~/Desktop/MyApp$ touch test.txt~/Desktop/MyApp$ echo Hello test01>test.txt~/Desktop/MyApp$ git add test.txt~/Desktop/MyApp$ git commit test.txt -m "init test.txt of test01"[test01 b323e2c] init test.txt of test01 1 file changed, 1 insertion(+) create mode 100644 test.txt# 在test02分支创建一个test.txt文件~/Desktop/MyApp$ git checkout test02Switched to branch 'test02'~/Desktop/MyApp$ touch test.txt~/Desktop/MyApp$ echo hello test02 > test.txt~/Desktop/MyApp$ git add test.txt~/Desktop/MyApp$ git commit test.txt -m "init test"[test02 fd1e225] init test 1 file changed, 1 insertion(+) create mode 100644 test.txt# 将分支test01合并到test02~/Desktop/MyApp$ git merge test01Auto-merging test.txtCONFLICT (add/add): Merge conflict in test.txtAutomatic merge failed; fix conflicts and then commit the result.# 通过git status可以查看冲突信息~/Desktop/MyApp$ git statusOn branch test02You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge)Unmerged paths: (use "git add
谢谢阅读!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~