Amir Rachum
Amir Rachum

Reputation: 79625

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 well this time).

Upvotes: 4

Views: 276

Answers (1)

Brian Campbell
Brian Campbell

Reputation: 332826

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.

Upvotes: 5

Related Questions