Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolving merge conflict in git pull?

I need help in resolving merge conflict in git pull from GitHub, I did following on my current branch, I did the following
fa

  1. git pull --rebase master
  2. git pull ssh:..... (pulled changes from my review)
  3. there was merge conflict in one file
  4. removed all conflicts
  5. git add .
  6. when I tried to commit back using git commit --amend I got error

"fatal: you are in the middle of merge -- cannot amend"

I want to amend same commit again without createating new commit ID. is there a way ?

like image 485
mahemad Avatar asked Mar 06 '26 11:03

mahemad


1 Answers

Given that your history looks like:

B    C1   C2
o----o----o master
      \
       o feature
       F

You can either rebase the changes from feature onto the branch you are pulling them in to (master) to make it a "fast-forward merge", creating linear history:

B    C1   C2   F
o----o----o----o master, feature

Or, in the stage you describe you can run git commit (without --amend) to proceed to create a commit recording the result of the merge:

B    C1   C2   M
o----o----o----o master
      \       /
        --o--  feature
          F

If you prefer to have an explicit merge commit to denote that you merged a feature branch you can rebase and then merge using the --no-ff flag, creating something like this:

B    C1   C2        M
o----o----o---------o master
           \       /
             --o--  feature
               F

Which variant you pick is up to you to decide; all three are valid. I typically prefer to rebase feature branches, so as to avoid having to solve merge conflicts in a separate commit (the merge commit). Keeping the history linear (no merges) or not is a matter of workflow and taste.

like image 169
jsageryd Avatar answered Mar 08 '26 06:03

jsageryd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!