git pull 后如何解决冲突?

发布于 2024-08-04 18:49:34 字数 809 浏览 6 评论 0原文

我必须在 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.

所以我用谷歌搜索了一下,发现人们说使用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 的版本覆盖所有内容怎么办?

I have to solve some conflict after a 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
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 pull to overwrite everything?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我们只是彼此的过ke 2024-08-11 18:49:35

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

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

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

 git fetch
 git reset --hard origin/your-branch-name
心凉怎暖 2024-08-11 18:49:35

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

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.

酒废 2024-08-11 18:49:35

如果您有适当的分支策略(即,在合并或变基等之前将功能合并到开发中),最常见的是当您想在分支上运行 git pull 时。您基本上希望从 Git 服务器获取所有新内容,然后应用您自己的内容,这在 Git 通用语言中是这样的:

# 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

除了存储之外,您还可以将当前状态放入临时分支中,但如果有的话是否存在冲突,您最终必须手动解决它们。

If you have a proper branching strategy (i.e. features are merged into develop, just before merging or rebasing etc.), most often when you want to run a git pull on a branch. You basically want to get all the new stuff from the Git server and later on apply your own stuff, which in Git lingua franca is something like this:

# 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

Instead of stashing, you could also put your current state into a temporary branch, but if there are conflicts you would have to manually resolve them eventually.

浅笑轻吟梦一曲 2024-08-11 18:49:34

为此,您不需要 mergetool。它可以很容易地手动解决。

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

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


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

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 add the affected files and commit to complete the merge.

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 add it.


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.

对岸观火 2024-08-11 18:49:34

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

尝试:

git mergetool -t gvimdiff

当然,您可以使用您喜欢的合并工具而不是我的 gvimdiff。梅德也太棒了...

I think you just forgot the -t switch at your command line. According to Git's help page, it stands for -t <tool>, --tool=<tool>, so it makes what you intended to.

Try:

git mergetool -t gvimdiff

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文