如今程序猿标配GIT做为代码管理,可是从SVN到GIT学习中,其中GIT的冲突是一个难点,经常会致使Push不上去,Pull不下来,很尴尬的地步,还不知道本身写的代码被覆盖没,废话很少说,直接上干货!php
采用SourceTree插件
和BeyondCompare
可视化解决冲突git
A 修改了conflict.file 中第1行内容而且提交到git上shell
B 这个时候也修改了confilct.file中第一行内容准备提交,这个时候git就会提示segmentfault
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拉取最新的代码。服务器
咱们pull一下,这个时候因为本地有修改这个文件,就会在本地产生冲突文件app
下载Beyond Comparesvn
打开SourceTree->工具->选项->比较->外部差别对比合并->选择BeyondCompare工具
在本地副本->右键->解决冲突->打开外部合并工具gitlab
和svn同样解决好冲突保存更改,退出便可学习
拉取时出现以下提示:
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 * branch develop -> FETCH_HEAD Updating b0c5c94..40cef3b error: Your local changes to the following files would be overwritten by merge: server/conflict.file Please, commit your changes or stash them before you can merge. Aborting
提示须要暂存本地修改,才能拉取服务器上新的代码
点击贮存(英文版:Stash),随便起一个名字,里面存的都是距离上次服务器版本到本地修改之间的差别,千万别删掉了,合并成功无误了再删掉。
pull拉取服务器代码,这个时候,本地的代码变成了服务器上的代码。
点击贮藏->应用贮藏区 ,这个时候是把以前的修改合并到本地上,这个时候会提示冲突。
git -c diff.mnemonicprefix=false -c core.quotepath=false stash apply stash@{0} Auto-merging server/conflict.file CONFLICT (content): Merge conflict in server/conflict.file
能够在sourcetree里看到有感叹号,表明冲突文件,和上面解决冲突方法相似,可是稍微不一样,最左边成了远程版本,中间为远程上一个版本,最后才是本地修改。
这个是和咱们操做方式有关:咱们是先暂存本地修改,先拉取远程代码,这个时候local 就成了远程代码,最后咱们用暂存的合并进去,remote就成了本地修改
这个是因为git自身形成的 它会解决冲突后 生成一个原来冲突的备份,咱们能够去掉
git config --global mergetool.keepBackup false