1

Given

  • branch development to be merged into integration
  • both branches do no permit push
  • while merging there is a conflict
$ git merge development
Auto-merging .gitlab-ci.yml
CONFLICT (content): Merge conflict in .gitlab-ci.yml
Automatic merge failed; fix conflicts and then commit the result.

STEP #1 Create a temporary branch from integration, and merge development

$ git checkout integration
$ git checkout -b patch-1
$ git merge development
Auto-merging .gitlab-ci.yml
CONFLICT (content): Merge conflict in .gitlab-ci.yml
Automatic merge failed; fix conflicts and then commit the result.

STEP #2 After fixing the conflicts manually, push temporary branch to origin

$ git push --set-upstream origin patch-1

STEP #3 Raise merge request from patch-1 into integration. This gets merged successfully without conflicts.

STEP #4 Re-try merging development branch into integration,

$ git merge development
Auto-merging .gitlab-ci.yml
CONFLICT (content): Merge conflict in .gitlab-ci.yml
Automatic merge failed; fix conflicts and then commit the result.

At the end, I still get the same merge conflict.

  • Any problem with this strategy ?
  • Suggestions for corrections

Adding git log between two branches

$ git log --graph --oneline development origin/development integration origin/integration
*   3ae0efe (origin/integration, integration) Merge branch 'patch-1' into 'integration'
|\
| * c393837 Comment-01
|/
*   2a77f4f Merge branch 'release' into integration
|\
| *   67f7ed6 (release) Merge branch 'integration' into 'release'
| |\
| | * e15411f Comment-02
| |/
| *   d5ec084 Merge branch 'integration' into 'release'
| |\
| | * 6540f71 Comment-02
| |/
| *   064b304 Merge branch 'integration' into 'release'
| |\
| | * 8def831 Comment-02
| |/
| *   4214907 Merge branch 'integration' into 'release'
| |\
| | * da7c967 Comment-02
| |/
* |   b0bfb25 Merge branch 'development' into 'integration'
|\ \
| * | 75e4d3d 
|/ /
* |   56ae216 (origin/feature/rbac-on-rbac-data) Merge branch 'development' into 'integration'
|\ \
* \ \   3ca4d3b Merge branch 'development' into 'integration'
|\ \ \
* \ \ \   9df80be Merge branch 'development' into 'integration'
|\ \ \ \
* \ \ \ \   9c9718c Merge branch 'release' into integration
|\ \ \ \ \
| | |_|_|/
| |/| | |
| * | | |   94f6141 Merge branch 'integration' into 'release'
| |\ \ \ \
| | * | | | 99fddaf Comment-02
| |/ / / /
| * | | |   5e69629 Merge branch 'integration' into 'release'
| |\ \ \ \
| | * | | | bd2dc44 Comment-02
| |/ / / /
* | | | |   d704342 Merge branch 'development' into 'integration'
|\ \ \ \ \
* \ \ \ \ \   c62b668 Merge branch 'development' into 'integration'
|\ \ \ \ \ \
| | | | | | | *   fdbd3f4 (HEAD -> development, origin/development) Merge branch 'feature/two' into 'development'
| | | | | | | |\
| | | | | | | | * 840cbaf Feature Two
| | | | | | | |/
| | | | | | | *   8dd03dd Merge branch 'feature/one' into 'development'
| | | | | | | |\
| | | | | | | | * 8549cba Comment-01
| | | | | | | |/
| | | | | | | *   fbc75d4 Merge branch 'feature/one' into 'development'
| | | | | | | |\
| | | | | | | | * a233226 Comment-01
| | | | | | | |/
| | | | | | | *   f774d98 (tag: oct20.v1) Merge branch 'configuration/change-01' into 'development'
| | | | | | | |\
| | | | | | | | * 649ae41 Comment-03
| | | | | | | |/
| | | | | | | *   a7ab4d8 Merge branch 'configuration/change-01' into 'development'
| | | | | | | |\
| | | | | | | | * eae0789 Comment-03
| | | | | | | |/
| | | | | | | *   dc61af9 Merge branch 'defect-importdata-workday-exception' into 'development'
| | | | | | | |\
| | | | | | | | * 5842e04 Defect importdata workday exception
| | | | | | | |/
| | | | | | | * 0719f2e Merge branch 'hotfix-01' into 'oct20-dev-release'
| | | | | | |/|
| | | | | | | * a226119 (origin/hotfix-01, hotfix-01) 
| | | | | | |/
| | | | | | * 1a14721 Comment-04 <======= Git merge-base commit
soufrk
  • 825
  • 1
  • 10
  • 24
  • Just checking : did you update your local `integration` branch before retrying the merge? If not, your local ref still points to the old ref, which would explain such behaviour. In this case, just `git pull` from your local `integration` branch. Then it should not raise conflicts any more upon merging `development`. – Romain Valeri Oct 13 '20 at 13:00
  • Yes, I have done that. As a matter of fact I have even done `reset --hard` to have them exactly as origin. – soufrk Oct 13 '20 at 13:06
  • After step #3 wouldn't `integration` already contain `development`? You created `patch-1` from `integration`, merged `development` in it and then merged back `patch-1` (through request) into `integration`. At this point `development` is behind `integration` and already has been conceptually merged into it, no? – plalx Oct 13 '20 at 13:30
  • Is it possible that `development` was updated between your operations ? Inspect the history to see how these branches are set up (both local and remote): try `git log --graph --oneline development origin/development integration origin/integration` – LeGEC Oct 13 '20 at 14:28
  • @plalx Even I'm having the same understanding – soufrk Oct 13 '20 at 15:21
  • @LeGEC I have ensured that, I'm the only person working – soufrk Oct 13 '20 at 15:21
  • @soufrk Well in that case why would you do step `#4`? You are obviously going to run into conflicts if the branch was already merged and conflicts were solved in a merge commit. You just need to fast forward `development` to `integration`, not merge `development` into `integration` again. – plalx Oct 13 '20 at 15:38
  • Double check the history of your branches : somehow git doesn't consider that `development` is an ancestor of `integration`. – LeGEC Oct 13 '20 at 17:40
  • @LeGEC Firstly, I had created `development` from `integration`. Moreover, I did `git merge-base integration development`. With the resulting commit-id, I looked up in GitLab for details. It shows both branches' names in parent list. Any other way you suggest ? – soufrk Oct 14 '20 at 07:42
  • @soufrk : that's on gitlab (the remote). `git merge development`, if I understand correctly, is run on your local repo. Inspect your local history to see what git deals with when you run local commands. Can you add the output of `git log --graph --oneline development origin/development integration origin/integration` to your question ? – LeGEC Oct 14 '20 at 07:46
  • @LeGEC added log history. Comments are simplified and made anonymous – soufrk Oct 14 '20 at 08:35

1 Answers1

1

As you can see in your graph : somehow, branch development was not merged into integration

  • the current head of development is :
*   fdbd3f4 (...) Merge branch 'feature/two' into 'development'
|\
| * 840cbaf Feature Two
...

which is not an ancestor of branch integration (there is no line going from development to integration).

The last commit on integration mentions a merge :

* 3ae0efe (...) Merge branch 'patch-1' into 'integration'
|\
| * c393837 Comment-01
|/
*   2a77f4f Merge branch 'release' into integration
...

but it looks like this merge only brought a single commit (c393837) instead of the complete history of development.

This is why you still have conflicts when merging development into integration.


If you know for a fact that commit 3ae0efe (the head of integration) contains the full content of development merged into integration, you can create a fake merge commit to combine the histories.

But that's for you to know, by inspecting the actual content of your repo : since the two branches are split, git does not know that.

Otherwise : you will have to re-merge development into integration.


[edit]

You're using gitlab, and you merge your MRs using the "squash & merge" option, correct ?

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • But there are lots of commits that say Merge branch development into integration. How do we explain those? Did the OP keep deleting development and making a new one? Or doing some weird reset? – matt Oct 14 '20 at 19:04
  • Yes, I am using `squash commits` while merging. Is it because of squash commits that this can occur ? And the branches mentioned are long running branches. I need to go long back into time, to find out actual paths. Do shed light on **fake commit method** – soufrk Oct 14 '20 at 20:52