I have modified two files a
, b
in the last commit. But file b
should not be commited, what's the workflow to amend this?
How to amend the last commit to un-add a file
git
git
I have modified two files a
, b
in the last commit. But file b
should not be commited, what's the workflow to amend this?
Best Answer
Update (couple of years later)
Jan Hudec
True: you can reset a file to its index content easily enough, as the more recent answer (written by Matt Connolly) suggests:
HEAD^
allows the file to access its content in the previous commit before the last one.Then you can
git commit --amend
, as I originally wrote below.With Git 2.23 (August 2019), you might use the new
git restore
commandshorter:
Again, you then can
git commit --amend
, as I originally wrote below.Original answer (January 2011)
If this is your last commit (and you haven't pushed it anywhere), you can amend it:
(first stash or save
b
)Then delete b, re-commit. Restore b and you're done.