现在程序猿标配GIT作为代码管理,但是从SVN到GIT学习中,其中GIT的冲突是一个难点,常常会导致Push不上去,Pull不下来,很尴尬的地步,还不知道自己写的代码被覆盖没,废话不多说,直接上干货!
亮点
采用SourceTree插件
和BeyondCompare
可视化解决冲突
方法
构造冲突
To git@192.168.x.xxx:xxx/server-aggregator.git
! [rejected] develop -> develop (fetch first)
error: failed to push some refs to 'git@192.168.xx.xx:xxx/server-aggregator.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.
提示远程已经有更新了,本地版本太低,让我们先pull拉取最新的代码。
配置外部比较工具
解决冲突
另外一种情况
it -c diff.mnemonicprefix=false -c core.quotepath=false pull local-server-aggregator develop
/opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-shell:3: warning: Insecure world writable dir /usr in PATH, mode 040777
From 192.168.0.200:weitoo/server-aggregator
Auto-merging server/conflict.file
CONFLICT (content): Merge conflict in server/conflict.file
可以在sourcetree里看到有感叹号,代表冲突文件,和上面解决冲突方法类似,但是稍微不同,最左边成了远程版本,中间为远程上一个版本,最后才是本地修改。
这个是和我们操作方式有关:我们是先暂存本地修改,先拉取远程代码,这个时候local 就成了远程代码,最后我们用暂存的合并进去,remote就成了本地修改
多余的.orig文件
这个是由于git自身造成的 它会解决冲突后 生成一个原来冲突的备份,我们可以去掉
git config --global mergetool.keepBackup false
原文出处 : http://mousycoder.com/2015/10/14/git-source-conflict-reslove-solution/