Reputation: 659
I have a few files I made changes to.
Then I committed it and realized I made a change to a file I didn't want to change. How can I get the file back to its original state? I am on a branch.
git checkout --file
didn't do anything at all.
Upvotes: 26
Views: 43227
Reputation: 11
You can try this :
git checkout origin/<your-main-branch> -- filename
Upvotes: -1
Reputation: 196
It isnt very clear to me what you mean by the original state. In my case however, the original state that I wanted to go back to was that of the master branch (off which I had branched off into a dev branch).
So to 'revert' a file.txt to the master branch version while checked out on a different dev branch, run:
git checkout master <full-path-to-file>\file.txt
Upvotes: 4
Reputation: 91837
git checkout filename
will work in most cases, unless you have a branch with the same name as a file. In either case,
git checkout -- filename
will be sufficient.
Upvotes: 44
Reputation: 141770
You need a space between --
and your filename:
git checkout -- filename
Upvotes: 6