nogeek001 nogeek001 - 2 months ago 27
Git Question

undo or revert git am --resolved

I was manually applying the patch and after I was done I did the following

git add .
git am --resolved

I had overlooked the part that the rej file was also present and was untracked but
git add .
added all the files to the staging area as expected and on
git am --resolved
I ended up committing my rej file which had the patch diffs .

I did a
git reset --soft HEAD^
so I could revert the commit and just commit the file modified by the patch .

But the issue now is that commit message and author would not be extracted from the patch file anymore since I did a git commit.

How do I undo a git resolved so I could remove the rej file and resolve again so the commit messages and author are intact?


It sounds like there is only one commit in the patch.

The easiest way in this case (just the one commit) is to git reset back to the incorrect commit, then remove the extra file (git rm ...) and use git commit --amend. The --amend option tells git commit to re-use the existing message and author, and make a new commit from the current index, shoving the old commit aside.

If there are multiple commits, all containing the .rej file, you will need to use Leon's answer or something similar (e.g., a longer manual rebase). You may wish to limit the set of commits copied by git filter-branch since filtering copies every such commit, which is very slow.

To reset back to the incorrect commit, use git reset --soft HEAD@{1} as Leon said.