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


当前回答

如果您不使用工具合并,首先复制您的代码:

- `checkout master`
- `git pull` / get new commit
- `git checkout` to your branch
- `git rebase master`

它解决冲突,你可以复制你的代码。

其他回答

如果您不使用工具合并,首先复制您的代码:

- `checkout master`
- `git pull` / get new commit
- `git checkout` to your branch
- `git rebase master`

它解决冲突,你可以复制你的代码。

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

使用耐心

对于一个大合并冲突,使用耐心为我提供了良好的结果,它会试图匹配区块而不是个别的线条。

例如,如果您更改您的程序的定位,默认 Git 合并策略有时匹配单手 { 属于不同的功能。

git merge -s recursive -X patience other-branch

从文档中:

With this option, merge-recursive spends a little extra time to avoid 
mismerges that sometimes occur due to unimportant matching lines 
(e.g., braces from distinct functions). Use this when the branches to 
be merged have diverged wildly.

与共同祖先相比

如果你有一个合并冲突,想要看到其他人在修改分支时想知道什么,有时更容易将他们的分支直接与普通祖先(而不是我们的分支)进行比较。

git diff $(git merge-base <our-branch> <their-branch>) <their-branch>

通常,您只希望看到特定文件的更改:

git diff $(git merge-base <our-branch> <their-branch>) <their-branch> <file>

请遵循以下步骤来解决 Git 中的合并冲突:

查看 Git 状态: git 状态 获取 patchset: git fetch (从您的 Git commit 查看正确的 patch) Checkout 一个本地分支(temp1 在我的例子中在这里): git checkout -b temp1 Pull 最近的内容从主: git pull -rebase 起源主 启动 mergetool 并检查冲突并纠正它们......并检查与您当前分支的远程分支中的变化: git mergetool Chec

我跟随下面的过程。

解决合并冲突的过程:

首先,把最新的从目的地分支到你想合并 git pull 起源开发 随着你得到最新的从目的地,现在解决冲突手动在一个 IDE 通过删除这些额外的字符。

这就是它,你会看到它在你的拖请求中解决,如果你使用Bitbucket或GitHub。