I've made some changes to a specific file in a repository, and committed those changes. All under one commit.
In that one commit, I also made changes to several other files. How do I unstage the changes I made to that one specific file and not all of the files that were changed in the commit?
Unstage isn't exactly the right word here - that refers to removing changes from the index (the staging area), with the implication that they haven't been committed.
Since your changes have been committed, what you're asking how to do is check out the version of the file from the previous commit:
git checkout HEAD^ path/to/file
HEAD
is the current commit, and HEAD^
is the first parent of HEAD
.
If you have not yet pushed the commit anywhere:
$ git checkout HEAD^ path/to/revert
This will restore the path you wanted to revert to the state it was in as of the prior commit. (It will revert any changes made in the last commit you made.)
The index will also be updated, so now you just have to amend your commit:
$ git commit --amend
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With