Git: restore my changes which were amended to merge commit
You have 2 SHAs that are of interest here - the original merge commit, and the amended merge commit. What you want to do is git reset
your HEAD
to the original merge commit, while preserving your index and working directory. You can then create a new commit hanging off the merge commit.
Use
git reflog
to find the SHA of the original merge commit
reset to the commit with
git reset ORIGINAL_MERGE_COMMIT_SHA
or directly from reflog with git reset HEAD@{X}
where X is 1 or the position in the reflog that represents the merge commit.
You should now be ready to git commit
your original changes and don't pass in --amend here and you will create a new commit.
I've found one way which works:
git diff HEAD~1 > p.patch
git checkout master
git checkout -b branch-name
Manually edit p.patch to remove unrelated changes from merge.
git apply p.patch
But I suspect there is a much easier/better way to do it.