git pull 后如何解决冲突?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1435754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:03:31  来源:igfitidea点击:

How do I resolve a conflict after git pull?

gitconflictgit-mergegit-pull

提问by Tim

I have to solve some conflict after a git pull.

之后我必须解决一些冲突git pull

$ git pull
CONFLICT (rename/add): Renamed vignette_generator_mashed.h->vision_problem_8.h in 49423dd0d47abe6d839a783b5517bdfd200a202f. vision_problem_8.h added in HEAD
Added as vision_problem_8.h~HEAD_1 instead
Removed vignette_generator_cross_square.cc
Automatic merge failed; fix conflicts and then commit the result.

So I googled it a bit, and found people saying using git mergetool. But here is what I got:

所以我用谷歌搜索了一下,发现有人说使用git mergetool. 但这是我得到的:

$ git mergetool
merge tool candidates: meld kdiff3 tkdiff xxdiff meld gvimdiff emerge opendiff emerge vimdiff
No files need merging
$ git mergetool opendiff
merge tool candidates: meld kdiff3 tkdiff xxdiff meld gvimdiff emerge opendiff emerge vimdiff
opendiff: file not found

So does it mean I have to install something?

那么这是否意味着我必须安装一些东西?

What if I simply want the version from git pullto overwrite everything?

如果我只是想让版本git pull覆盖所有内容怎么办?

采纳答案by Phil Miller

You don't need mergetool for this. It can be resolved pretty easily manually.

为此,您不需要合并工具。它可以很容易地手动解决。

Your conflict is that your local commits added a file, vision_problem_8.h, that a remote commit also created, by a rename from vignette_generator_mashed.h. If you run ls -l vision_problem_8.h*you will probably see multiple versions of this file that git has preserved for you. One of them will be yours, another of them will be the remote version. You can use an editor or whatever tools you like to resolve the conflicting contents. When you're done, git addthe affected files and commit to complete the merge.

您的冲突是您的本地提交添加了一个文件,vision_problem_8.h远程提交也创建了一个文件,通过从vignette_generator_mashed.h. 如果您运行,ls -l vision_problem_8.h*您可能会看到 git 为您保留的此文件的多个版本。其中一个将是您的,另一个将是远程版本。您可以使用编辑器或任何您喜欢的工具来解决冲突的内容。完成后,git add提交受影响的文件并提交以完成合并。

If you just want to use the remote commit's version, then you can just move the copy that you didn't write into place and git addit.

如果您只想使用远程提交的版本,那么您可以将未写入的副本移动到位git add



Regarding the merge tools, have a look at git help mergetool. Basically, it's going to try running each of the included possibilities until it finds one, or use one you have explicitly configured.

关于合并工具,请查看git help mergetool. 基本上,它将尝试运行每个包含的可能性,直到找到一个,或者使用您明确配置的一个。

回答by mano2a0c40

I think you just forgot "-t" switch at your command line. According git help page it stands for "-t , --tool=" so it makes what you intended to.

我想您只是忘记了命令行中的“-t”开关。根据 git 帮助页面,它代表“-t ,--tool=”,因此它符合您的意图。

Try:

尝试:

git mergetool -t gvimdiff

Of course you may use your prefered merge tool instead of mine gvimdiff, meld is great too...

当然,您可以使用您喜欢的合并工具而不是我的 gvimdiff,meld 也很棒......

回答by BlueHyman

If you run your merge from a subdirectory of your project, git will run the merge for your whole project. However, mergetool can only see (and merge) files in or below the working directory. So, if this scenario occurs, make sure you are trying to run your conflict resolution from the top-level directory in your project.

如果您从项目的子目录运行合并,git 将为您的整个项目运行合并。但是,mergetool 只能查看(和合并)工作目录中或以下的文件。因此,如果发生这种情况,请确保您尝试从项目的顶级目录运行冲突解决方案。

回答by saferJo

What if I simply want the version from git pull to overwrite everything?If you want just that you should use:

如果我只是想让 git pull 中的版本覆盖所有内容怎么办?如果您只想这样做,您应该使用:

 git fetch
 git reset --hard origin/your-branch-name