Restoring a specific file from a commit
I'm using Git with GitGUI.
I did a commit to several files (and have since committed again) and now I see a test is not working. I checked out some commits and found the culprit. I now want to restore the changes made to a specific file, back to a certain commit. How can I do that?
A preferred solution will also keep the latest commits in the tree (so I can re-implement them 开发者_Go百科well this time).
You can pass a revision and filename to git checkout
to check out a particular version of that file:
git checkout abc123 -- filename
Now your working copy will have the version of filename
from commit abc123
, and you can commit that in order to restore back to that version of that file.
精彩评论