Home > Back-end >  Trying to simulate a git merge conflict
Trying to simulate a git merge conflict

Time:04-30

I am trying to simulate a simple merge conflict, having read about similar tasks on the website, my situation is slightly different.

Here are the steps that i am taking.

I have the develop branch

  • create Branch1 from develop branch

  • create Branch2 from develop branch

  • made changes on Branch1, stage and commit changes.

  • made changes on Branch2, stage and commit changes.

whilst checked out of Branch1, run the command git merge origin/Branch1 I get the message

git merge origin/feature/Branch1

Already up to date.

I am unsure as to what I am doing incorrectly here, the way the develop branch is setup, commits can only be made via a pull request, if i can illustrate a git conflict without the need for a pull request, that would be much simpler.

CodePudding user response:

A couple reasons why the simulation might not work:

  • What you're doing is merging from origin. In your steps, you didn't push anything, so there wouldn't be any updates on origin that would conflict with your current branch. Instead, (in this simulated case) merge from your local branch, to have the latest updates.

  • What changes do you do? You need to make sure you change the same lines in the same file in order to trigger a conflict.

  • Make sure you merge the right branches. If you merge branch1 and origin/branch1, in this simulation, there won't be any conflicts.

CodePudding user response:

As per the Git documentation:

[git merge] Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch. This command is used by git pull to incorporate changes from another repository and can be used by hand to merge changes from one branch into another.

[...]

Then git merge topic will replay the changes made on the topic branch since it diverged from master

In order for this command to work, move to the develop branch, then try merging again.

  •  Tags:  
  • git
  • Related