git解决冲突与merge

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

                       

git冲突的场景与其他SCM工具一样,我在这边修改了文件a,同事也修改了文件a。同事比我先提交到仓库中,那么我pull代码时就会报错:

$ git pullremote: Counting objects: 39, done.remote: Compressing objects: 100% (30/30), done.remote: Total 39 (delta 13), reused 0 (delta 0)Unpacking objects: 100% (39/39), done.From https://code.csdn.net/lincyang/androidwidgetdemo   d3b2814..5578b8c  master     -> origin/masterUpdating d3b2814..5578b8cerror: Your local changes to the following files would be overwritten by merge:    app/src/main/AndroidManifest.xml    app/src/main/java/com/linc/skill/screenswitch/ScreenSwichActivity.javaPlease, commit your changes or stash them before you can merge.Aborting
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

而此时我又不顾这个错误,将我的代码add并commit,然后push时报如下错:

To https://code.csdn.net/lincyang/androidwidgetdemo.git ! [rejected]        master -> master (non-fast-forward)error: failed to push some refs to 'https://code.csdn.net/lincyang/androidwidgetdemo.git'hint: Updates were rejected because the tip of your current branch is behindhint: its remote counterpart. Integrate the remote changes (e.g.hint: 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

然后我有执行了git pull:

$ git pullAuto-merging app/src/main/java/com/linc/skill/screenswitch/ScreenSwichActivity.javaCONFLICT (content): Merge conflict in app/src/main/java/com/linc/skill/screenswitch/ScreenSwichActivity.javaAuto-merging app/src/main/AndroidManifest.xmlCONFLICT (content): Merge conflict in app/src/main/AndroidManifest.xmlAutomatic merge failed; fix conflicts and then commit the result.
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

那么既然两个文件冲突,我就可以借助mergetool来搞定它。我安装了meld作为代码比对工具,那么它理所当然也就成为我的mergetool了。

$ git mergetoolThis message is displayed because 'merge.tool' is not configured.See 'git mergetool --tool-help' or 'git help config' for more details.'git mergetool' will now attempt to use one of the following tools:meld opendiff kdiff3 tkdiff xxdiff tortoisemerge gvimdiff diffuse diffmerge ecmerge p4merge araxis bc3 codecompare emerge vimdiffMerging:app/src/main/AndroidManifest.xmlapp/src/main/java/com/linc/skill/screenswitch/ScreenSwichActivity.javaNormal merge conflict for 'app/src/main/AndroidManifest.xml':  {local}: modified file  {remote}: modified fileHit return to start merge resolution tool (meld): Normal merge conflict for 'app/src/main/java/com/linc/skill/screenswitch/ScreenSwichActivity.java':  {local}: modified file  {remote}: modified fileHit return to start merge resolution tool (meld): 
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

merge完成后,执行git status发现有些文件做了修改,那么把这些文件提交 吧,就把这次commit作为一次merge操作吧。

$ git commit -m "merge"[master 978aa1f] merge$ git pushCounting objects: 64, done.Delta compression using up to 4 threads.Compressing objects: 100% (25/25), done.Writing objects: 100% (33/33), 3.81 KiB | 0 bytes/s, done.Total 33 (delta 15), reused 0 (delta 0)To https://code.csdn.net/lincyang/androidwidgetdemo.git   5578b8c..978aa1f  master -> master$ git pullAlready up-to-date.
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

至此,本次冲突解决完毕。

如果希望保留生产服务器上所做的改动,仅仅并入新配置项, 处理方法如下:

git stashgit pullgit stash pop
  
  
  • 1
  • 2
  • 3

参考:
http://www.cnblogs.com/sinojelly/archive/2011/08/07/2130172.html

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值