Git SourceTree 冲突解决方案
2017-04-19 09:39
423 查看
Git现在越来越火,很多人都从Svn迁移到Git上面,Git让我们更加与世界接轨,不再是“局域网”的程序猿,特别是掌握了Git之后,会发现它真的很好用,本文对Git中比较烦人的冲突进行了详细的说明,希望能帮助那些刚接触Git的程序猿。
采用可视化SourceTree插件beyondCompare更加接近svn冲突比较
A 修改了conflict.file 中第1行内容并且提交到git上
B 这个时候也修改了confilct.file中第一行内容准备提交,这个时候git就会提示
提示远程已经有更新了,本地版本太低,让我们先pull拉取最新的代码,
我们继续拉取代码pull一下,这个时候由于本地有修改这个文件,就会在本地产生冲突文件
下载地址:http://www.scootersoftware.com/download.php
打开sourcetree->工具->选项->比较->外部差异对比合并->选择BeyondCompare
在本地副本->右键->解决冲突->打开外部合并工具
和svn一样解决好冲突保存更改,退出即可
拉取时出现如下提示:
提示需要暂存本地修改,才能拉取服务器上新的代码
点击贮存(英文版:Stash),随便起一个名字,里面存的都是距离上次服务器版本到本地修改之间的差异,千万别删掉了,合并成功无误了再删掉。
pull拉取服务器代码,这个时候,本地的代码变成了服务器上的代码
点击贮藏->应用贮藏区 ,这个时候是把之前的修改合并到本地上,这个时候会提示冲突
可以在sourcetree里看到有感叹号,代表冲突文件,和上面解决冲突方法类似,但是稍微不同,最左边成了远程版本,中间为远程上一个版本,最后才是本地修改。
这个是和我们操作方式有关:我们是先暂存本地修改,先拉取远程代码,这个时候local 就成了远程代码,最后我们用暂存的合并进去,remote就成了本地修改
这个是由于git自身造成的 它会解决冲突后 生成一个原来冲突的备份,我们可以去掉
感谢您的耐心阅读,如果您发现文章中有一些没表述清楚的,或者是不对的地方,可以给我留言
,当然你有其他类的需求文章,也可以私信我。
亮点:
采用可视化SourceTree插件beyondCompare更加接近svn冲突比较
构造冲突
A 修改了conflict.file 中第1行内容并且提交到git上B 这个时候也修改了confilct.file中第一行内容准备提交,这个时候git就会提示
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一下,这个时候由于本地有修改这个文件,就会在本地产生冲突文件
配置外部比较工具
下载地址:http://www.scootersoftware.com/download.php打开sourcetree->工具->选项->比较->外部差异对比合并->选择BeyondCompare
解决冲突
在本地副本->右键->解决冲突->打开外部合并工具和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就成了本地修改
生成了多余的.orig文件
这个是由于git自身造成的 它会解决冲突后 生成一个原来冲突的备份,我们可以去掉git config --global mergetool.keepBackup false
感谢您的耐心阅读,如果您发现文章中有一些没表述清楚的,或者是不对的地方,可以给我留言
,当然你有其他类的需求文章,也可以私信我。
相关文章推荐
- Git SourceTree 冲突解决方案
- Git SourceTree 冲突解决方案
- SourceTree + Beynod Compare解决Git冲突的方法
- Git本地项目上传 & SourceTree & GitHub 简单使用
- 【Git+Source Tree使用教程之四】Reset
- git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree fetch origin
- Eclipse上GIT插件EGIT使用手册-——冲突解决方案
- 团队合作开发git冲突解决方案 Intellij IDEA
- Git+SourceTree+Github
- 【Git+Source Tree使用教程之二】Branching & Merging
- 【Git+Source Tree使用教程之一】commit & push
- Intelij IDEA管理git之远程代码冲突解决方案
- Getting started with SourceTree, Git and git flow
- Git SourceTree 冲突解决方案
- Git工具比较:sourcetree tortoisegit
- 【Git+Source Tree使用教程之三】Git Workflow
- mac+git+SourceTree > windows+subversion+TortoiseSVN
- Git + SourceTree + Eclipse + Dashboard(服务器端)的代码管理
- GitLal+sourceTree版本管理
- Git的好伙伴:SourceTree & BeyondCompare