I would like to amend a merge commit which failed a unit test on our continuous integration server, but I don't want to leave a commit which fails tests in the history.
Since this commit was only used by the CI server (and would not have been pulled down by anyone else) I would like to fix up the merge and then --force push it to replace the existing failed merge commit.
My problem is, I can't work out how to easily get back to the state immediately before the original commit was made, so that I can fix the failing test, recommit the merge and then force push that change up.
I don't really want to have to redo the whole merge, since there are quite a few files with conflicts which had to be resolved and all but one was resolved successfully.
What I have tried so far
Attempt 1: git reset
My first attempt was to do a mixed reset back to the commit before the merge commit, fix the bug introduced by the merge and then recommit.
git reset HEAD^ # Fix the failing test git commit Unfortunately this results in a non-merge commit which silently incorporates all of the branch changes - not really what I want. *8')
Attempt 2: reset, stash, merge & apply
I then attempted to use stash to save the changes I made during my first attempt to merge:
git reset HEAD^ git add . # Since there were untracked files git stash git merge branch git stash apply # Fails git add . git stash apply # Merged but with conflicts Unfortunately when git stash apply attempts to merge my stashed changes with the existing conflicted merge files it fails with the error
Cannot apply to a dirty working tree, please stage your changes
If I dutifully make my working directory clean by using git add . then the git stash apply runs but now not only do I have conflicts, I have conflicts with conflicts in them and any files which should have been removed have been added back in.
Attempt 3: amend and/or rebase.
I tried the nice simple suggestion by qqx to just fix the problem and git commit --amend the original commit, but without actually going back to the mid-merge state you lose access to the merge tools.
Once I've committed, I lose the ability to run git mergetool {file} as it just returns with the error:
{file}: file does not need merging
When trying to fix up a merge conflict, I really like being able to see my base, left, right and current revisions all together using tools like kdiff3.
using rebase suffers the same issue.
Any hints on a workflow which could allow me to achieve my desired result would be appreciated.