使用git pull冲突处理文件时和本地文件冲突怎么办

分享git的几个小技巧,后面会根据使用补充。目前包括git撤销本地修改、git回退到前n个版本、git多用户提交冲突解决、git push简化
推荐两个用了一年半的理财产品
我维护的Android经验分享的公众号&30篇
站内推荐文章
阿里、滴滴内推(20k-40k)*16月+
交流讨论区
平安集团 8% 理财产品
那些著名开源库的原理分析
翻.墙.—几十块钱换来大世界
(103,678)(70,141)(65,423)(62,312)(61,931)(54,516)(51,859)(51,306)(49,402)(45,228)
理财推荐-创办了 6 年的挖财
我维护的Android经验分享的公众号&30篇
平安集团 8% 理财产品
阿里、滴滴内推(20k-40k)*16月+对于解决 Git 的 Merge Conflict 你有哪些经验和技巧?
子问题:有哪些不错的 merge tool ?
按投票排序
贴一个在公司写的wiki page,
meld 很好用。Configuration
meld is a useful
three-way-compare merge tool. you can use it in Git.
(install meld)
git config --global merge.
(set Git merge tool default as meld)
When you merge a branch in Git, it may get into conflict state, if you need to go on, you need fix these conflict, but if you need to go back to the state before merge, you can you use
git reset -- (get me back)
If you want to fix the conflicts, use
我的经验:在特性分支上开发的过程中就要经常与主干分支进行rebase,能让你最后在合并代码的时候轻松很多。都知道集成是个很痛苦的事,各种冲突。与其把它放到最后让人痛苦,不如平时就抽出一些时间来解决这些问题。我习惯2~3天就和主干分支进行一次rebase,这个时候即使有冲突也是很好解决的。在分支开发完毕的时候进行最后一次rebase,然后在进行merge的时候不会有任何冲突了。
这样的问题我们就看看stackoverflow上都是怎么回答的好了,正好最近也遇到类似的问题。这个是关注和赞同最高的帖子:排名第一的答案是用 git mergetool. 还有这两个隐藏的很深的参数:git checkout --ours file 和 git checkout --theirs file。子问题关于mergetool的推荐:答案里已经有人说到用meld了。个人感觉kdiff3也不错,3-way merge的GUI工具。窗口的布局大概就是:还算简单明了,上方依次是base,local和remote三个版本的代码,下面是解决冲突后的代码,直接在下方冲突处来选择使用哪个版本。这里有篇关于kdiff3和meld的介绍:
(测了下国内好像可以访问)另外有些是在没法用工具解决的conflict只能手动改改了。最后附上:kdiff3的主页:meld的主页:
tortoisegit+beyondcompair,tortois的冲突文件列表窗口极度方便,一目了然,比在命令行下方便一万倍,至于BC,最好用的3路merge工具,没有之一,没有它简直没法用git。我一直停留在windows上的唯一理由就是其他平台上没有这么方便的git工具
我的经验是使用rebase。具体操作1.git add &FILE&
2.git commit ...
3.git pull --rebase (将你的版本加在最后的节点上)
如果有冲突,会提示你。冲突分为两种,一种是在不同地方的冲突,通常情况下,git是可以自己合并的。另外一种是因为可能是同一个文件的编辑,git没法自动合并,需要二选一,这时候打开冲突的文件,手动编辑文件到可用的版本。然后。。4.git rebase --continue
重复3,4直到所有的都solve5.git push
上传到remote,搞定!
这些git的用法,用多了就好了。我刚开始也是这样的。首先在pull的时候加上rebase,解决conflict,最后pushgit pull --rebase origin remoteif there is conflict, clean it and execute the following commandgit add . git rebase --continueif all be donegit push origin remote每次都用这种方式,就不会有错了。如果直接用merge命令也一样,记住要rebase就对了。如git merge feature-1234first pull master code. -& git pull --rebase origin remoteif conflict, clean it , then -& git add .; git rebase --continuecheckout to feature being merged to master branch -& git checkout feature-1234merge it to master branch -& git merge feature-1234push to master -& git push origin remote有多个conflict,也可用下面的命令git rebase --continuegit mergetoolgit rebase --continuegit mergetool
至少自己写的代码逻辑自己是清楚的备份自己的代码,还原冲突文件至最新。再将自己的代码逻辑尝试添加回去。
man git-rerere
Vim + fugitive.
source tree
已有帐号?
社交帐号登录
无法登录?
社交帐号登录git pull报错:Auto Merge F Fix Conflicts and Then Commit the Result.
1.出错场景:
协同开发时,我们从远程服务器上pull下代码的时候,出现以下提示信息:
Auto Merge F Fix Conflicts and Then Commit the Result.
2.原因分析:
利用git status,输出如下:
:/et git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 2 and 2 different commits each, respectively.
# Unmerged paths:
#&& (use &git add/rm &file&...& as appropriate to mark resolution)
#&&& both modified:&&&&& apt/sources.list
# Changes not staged for commit:
#&& (use &git add &file&...& to update what will be committed)
#&& (use &git checkout -- &file&...& to discard changes in working directory)
#&&& modified:&& cups/subscriptions.conf
#&&& modified:&& cups/subscriptions.conf.O
#&&& modified:&& mtab
#&&& modified:&& update-manager/release-upgrades
no changes added to commit (use &git add& and/or &git commit -a&)
从git status的结果可以发现:其中sources.list这个文件存在合并冲突
而进一步分析git pull的原理,实际上git pull是分了两步走的,(1)从远程pull下origin/master分支(2)将远程的origin/master分支与本地master分支进行合并
以上的错误,是出在了第二步骤
3.解决方法
方法一:如果我们确定远程的分支正好是我们需要的,而本地的分支上的修改比较陈旧或者不正确,那么可以直接丢弃本地分支内容,运行如下命令(看需要决定是否需要运行git fetch取得远程分支):
$:git reset --hard origin/master
或者$:git reset --hard ORIG_HEAD
&git-reset - Reset current HEAD to the specified state
&&&&&&&&&&&&&& Resets the index and working tree. Any changes to tracked files
&&&&&&&&&&&&&& in the working tree since &commit& are discarded.
方法二:我们不能丢弃本地修改,因为其中的某些内容的确是我们需要的,此时需要对unmerged的文件进行手动修改,删掉其中冲突的部分,然后运行如下命令
$:git add filename
$:git commit -m &message&
方法三:如果我们觉得合并以后的文件内容比价混乱,想要废弃这次合并,回到合并之前的状态,那么可以运行如下命令:
$:git reset --hard HEAD使用git pull文件时和本地文件冲突怎么办_百度知道
使用git pull文件时和本地文件冲突怎么办
提问者采纳
确定最后的代码,最好和冲突代码的提交者进行沟通发生冲突的时候,然后作出选择,你需要先解决冲突。把冲突代码review一遍。如果你不确定冲突如何解决。最后把代码合并之后再提交
其他类似问题
为您推荐:
git的相关知识
其他1条回答
冲突就合并呗。。。。。。
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 git pull 冲突 覆盖 的文章

 

随机推荐