我如何在我的 Git 存储库中解决合并冲突?


当前回答

GitLens for Visual Studio 代码

您可以尝试 GitLens for Visual Studio Code. 关键功能是:

3、轻松解决冲突

我喜欢这个特征:

此分類上一篇

第2章 现在的罪恶

此分類上一篇

第3章 错了

此分類上一篇

4、状态酒吧罪恶

此分類上一篇

有很多功能,你可以在这里查看。

其他回答

下面是可能的使用案例,从顶部:

你会拖一些变化,但哦,你没有到目前为止:

git fetch origin
git pull origin master

From ssh://gitosis@example.com:22/projectname
 * branch            master     -> FETCH_HEAD
Updating a030c3a..ee25213
error: Entry 'filename.c' not uptodate. Cannot merge.

所以你更新并尝试一次,但有冲突:

git add filename.c
git commit -m "made some wild and crazy changes"
git pull origin master

From ssh://gitosis@example.com:22/projectname
 * branch            master     -> FETCH_HEAD
Auto-merging filename.c
CONFLICT (content): Merge conflict in filename.c
Automatic merge failed; fix conflicts and then commit the result.

所以你决定看看这些变化:

git mergetool

哦,我的,哦,我的,上流改变了一些事情,但只是用我的变化......不......他们的变化......

git checkout --ours filename.c
git checkout --theirs filename.c
git add filename.c
git commit -m "using theirs"

然后,我们试着最后一次。

git pull origin master

From ssh://gitosis@example.com:22/projectname
 * branch            master     -> FETCH_HEAD
Already up-to-date.

是的!

识别哪些文件处于冲突中(Git应该告诉你这一点)。 打开每个文件并检查Difs; Git demarcates它们. 希望它将是显而易见的哪个版本的每个区块保持。 你可能需要讨论它与同开发人员谁承诺的代码. 一旦你解决了冲突在一个文件 git 添加到_file. 一旦你解决了所有冲突,做 git rebase --continue 或 whateve

查看 Stack Overflow 问题中的答案 堕胎在 Git 中的合并,特别是 Charles Bailey 的答案,显示如何查看不同版本的文件有问题,例如,

# Common base version of the file.
git show :1:some_file.cpp

# 'Ours' version of the file.
git show :2:some_file.cpp

# 'Theirs' version of the file.
git show :3:some_file.cpp

解决冲突的更安全的方式是使用 git-mediate (这里提出的常见解决方案是相当错误的 prone imho)。

查看此帖子,以便快速介绍如何使用它。

GitLens for Visual Studio 代码

您可以尝试 GitLens for Visual Studio Code. 关键功能是:

3、轻松解决冲突

我喜欢这个特征:

此分類上一篇

第2章 现在的罪恶

此分類上一篇

第3章 错了

此分類上一篇

4、状态酒吧罪恶

此分類上一篇

有很多功能,你可以在这里查看。