gpt4 book ai didi

git - 解决 git 冲突 : git mergetool doesn't work

转载 作者:太空狗 更新时间:2023-10-29 13:36:18 24 4
gpt4 key购买 nike

我需要解决git中的冲突,但是作为一个新手,不知道什么是最有效的方法。

这是我的情况:

enter image description here

我在 master 中,需要提交并推送我的所有更改。

$ git pull:

error: Your local changes to 'foo.cpp' would be overwritten by merge. Aborting. Please, commit your changes or stash them before you can merge.

有几个冲突的文件。当然,我在网上搜索了一下:

How to resolve merge conflicts in Git?

不幸的是,这两种解决方案都效果不佳。我可能会使用 stash(获取 diff 并使其干净)并进行手动解析,但我想使用 git mergetool 或 SourceTree。

这是我试过的:

$ git config merge.conflictstyle diff3
$ git mergetool
merge tool candidates: tortoisemerge emerge vimdiff
No files need merging
$ git mergetool -t vimdiff
No files need merging
$ git mergetool -t vimdiff foo
foo.cpp: file does not need merging
$ git diff foo.cpp
diff --git a/foo.cpp b/foo.cpp
index xxxxxx yyyyy
--- a/foo.cpp
+++ b/foo.cpp
@@ .....
..... <omitted>
$

我不确定哪里出了问题。 git mergetool 无法正常工作。它说不需要 merge 。但是,它显示差异并且 git pull 报告冲突。

Q1) 如何使用 mergetool 进行交互式冲突解决或 merge ?

Q2)是否可以使用SourceTree来解决冲突?我试过了,但也不直观。

谢谢!

最佳答案

您看到的错误:

error: Your local changes to 'foo.cpp' would be overwritten by merge. Aborting. Please, commit your changes or stash them before you can merge.

是因为您有未提交的更改(它在 SourceTree 显示的最顶部显示)。如果您有未提交的更改,任何 merge 尝试都将失败。您有三个选择:

  1. 取消所有更改(使用:git reset --hard)
  2. 存储所有更改(使用:git stash)
  3. 提交所有更改(使用:git add ...; git commit ...)

完成后,您将被允许 merge 。如果您选择上面的选项#3,那么可能会出现冲突;选项#1 或#2 不会有冲突。 [注意:对于选项 #2,您将稍后执行 git stash pop,然后可能会出现冲突。]

对于您的 Q1:执行 git config merge.tool diff3(或 vimdiff,或其他)。 merge 可能会造成混淆(它通常是 3 向 merge ,因此该工具显示三个版本和一个组合版本)。

对于您的问题 2:SourceTree 不包含它自己的 merge 工具;你需要依赖另一个(我使用 p4merge 和 SourceTree)。使用这些配置选项:

difftool.sourcetree.cmd=/Applications/p4merge.app/Contents/MacOS/p4merge "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
mergetool.sourcetree.cmd=/Applications/p4merge.app/Contents/MacOS/p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
mergetool.sourcetree.trustexitcode=true

关于git - 解决 git 冲突 : git mergetool doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15798063/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com