Fixing a merge commit in git

I messed up. I merged other branch to my branch. Changes on both sides were substantial so I spent extremely long time resolving conflicts. After committing the merge, I realized I had forgotten to add one file, so the merge was committed incomplete. I didn’t want to pollute the history with a “forgotten changes” commit so I decided to fix it before pushing. I called

git reset --soft HEAD~

Then I added the missed change and wanted to re-commit. However, git no longer knows it should be a merge commit. Is there any way out without re-doing the entire merge?

  • Git: How to list all (staged) files attempting to be committed
  • How can I manually run the hook post-receive on git?
  • Pygit2 - Merging a branch with no fast forward
  • 404 on Bluemix Toolchains
  • How to shallow clone a specific commit with depth 1?
  • Setting default diff algorithm does not translate to default merge algorithm (patience)
  • Can't Push Rails Project to Heroku
  • git file history browsing
  • Do git conflict resolution files not always represent every line in the source files?
  • How do I build Git on Solaris
  • Git commit stats per file
  • Re-use conflict resolution with Git
  • 2 Solutions collect form web for “Fixing a merge commit in git”

    What I would do, if I wanted to amend my last commit (whether it is a merge commit or a normal commit):

    1. Do the change (in your case add the file)
    2. Stage the change. E.g. with git add .
    3. Add the change to last commit with

      git commit –amend

    And you’re done

    Since you aren’t at that point anymore, first you have to go back there. How?

    1. List the last references you had in order to find out what was the hash of the merge commit you want to restore. Execute

      git reflog

    2. Search in that list and copy the hash of the merge commit. Look for something like […] merge origin/blablabal, just below something like […]reset moving to HEAD~

    3. Reset to that commit (as if you haven’t done the git reset --soft HEAD~)

      git reset –hard HASH_FROM_BULLET_2

    Now you are at the point you just commited the original merge and now you can proceed with 4, 5 and 6 from the beginning.

    you can checkout to a specific commit on a branch, therefore go back before the merge occured and redo it all.

    Go on merged branch :

    git log
    

    enter image description here

    will show all commits on branch with associated ids (or key) just copy the first letters of the desired commit key

    git checkout [commit_id you copied]
    

    You should now be on the branch before the merge.
    If you wish to continue browsing commits you can keep checkout from commit ids.

    Git Baby is a git and github fan, let's start git clone.