Is it possible to revert only a single file or certain changes in a file in multi file commit?
Full story I committed a bunch of files. A number of
I found a way to do this on the Git mailing list:
git show -- | git apply --reverse
Source: http://git.661346.n2.nabble.com/Revert-a-single-commit-in-a-single-file-td6064050.html#a6064406
That command fails (causing no changes) if the patch does not apply cleanly, but with --3way you instead get conflicts which you can then resolve manually (in this case Casey's answer might be more practical):
git show -- | git apply --reverse --3way
You can also use this to partially revert multiple commits, e.g.:
git log -S --patch | git apply --reverse
to revert files with changes matching in any commit. This is exactly what I needed in my use case (a few separate commits introduced similar changes to different files, along with changes other files in unrelated ways that I did not want to revert).
If you have diff.noprefix=true set in your ~/.gitconfig then you need to add -p0 to the git apply command, e.g.
git show -- | git apply -p0 --reverse