How can I merge conflicts between two branches with a common ancestor?

We recently encountered a really strange problem using git while trying to merge two branches. The situation is as follows:

  • branch Ais some long-lived branch that we want to merge back to the main trunk B, which has some other commits
  • We want to combine Bin A, and then Areturn toB
  • When we do git checkout A; git merge B, we encounter merge conflicts that are not related to changes made to A: they are located in a bunch of files that are supposedly not affected A, but changed inB
  • Using git annotateand git logtracking the pedigree of one of the conflicting files, we effectively observe that conflicting locations have a common binding the commit 1234: one line is annotated using the 1234in Aand 5678in B, but git annotate file1 5678^shows 1234for the conflicting lines.

I do not understand how this is possible, and cannot find any information on a similar problem anywhere.

+4
source share
1 answer

The conflict file must be changed on the branch Aafter the common pedigree with the branch B. And you can double check on git annotateand git logagain.

1. List the commits that modified the conflict file in branch A and branch B separately:

git annotate filename A
git annotate filename B

. git annotate () ().

, :

$ git annotate filename A
commit A1
commit A2
commit common
commit A3
commit A4

$ git annotate filename B
commit B1
commit B2
commit B3
commit common
commit B4

, commit ancestry commit common commit A3 A4 A; B commit B4.

2. git ,

, :

git log --oneline --decorate --graph --all -- filename

:

* commit A4 (branch A)
* commit A3
|   * commit B4 (branch B)
*   | commit Common
|  \
*   | commit A2
*   | commit A1
|   * commit B3
|   * commit B2
|   * commit B1
|   |
…   …
+1

Source: https://habr.com/ru/post/1692660/


All Articles