56

之后我必须解决一些冲突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.

所以我用谷歌搜索了一下,发现有人说 using 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

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

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

4

5 回答 5

25

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

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

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


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

于 2009-09-16T22:18:55.070 回答
7

我认为您只是在命令行中忘记了“-t”开关。根据 git 帮助页面,它代表“-t ,--tool =”,因此它可以实现您想要的。

尝试:

git mergetool -t gvimdiff

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

于 2012-10-08T19:20:24.370 回答
5

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

于 2010-02-16T18:52:37.687 回答
4

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

 git fetch
 git reset --hard origin/your-branch-name
于 2018-03-23T10:36:23.957 回答
0

如果您有适当的分支策略 - 也就是将功能合并到 develop 中,就在 merge rebased 等之前,最常见的是当您想 git pull在分支上运行时,您基本上想从 git 服务器获取所有新内容,并且稍后应用你自己的东西,这是 git lingua franca 是这样的:

# put all my changes on the stash 
git stash 

# fully reset the current branch to the state it is on the server
git clean -d -x -f ; git reset HEAD --hard ; git pull --force

# apply your own changes 
git stash pop

您也可以代替 stash 将当前状态放入 tmp 分支...但最终如果存在冲突,您将不得不手动解决它们...

于 2020-11-09T17:37:55.427 回答