Reputation: 78264
I made a change on my local master on one file. I checked it out from another branch.
I am in master branch
git checkout development /foo/file1.txt
I need to revert back to the original file. I tried to do git pull but it said I was already up to date. I did not add or commit the change.
What command do I use to get a clean/original copy of the file from the repository? Or the original copy from my local repository?
Thanks
Upvotes: 3
Views: 10827
Reputation: 1295
Since git v2.23 the preferred way to do this is:
git restore <filename>
Upvotes: 3
Reputation: 2081
If you want to just get a clean copy of a file (or revert back changes made to a file), do :
git checkout filename
This not only gets the copy from your local repo, but, the copy is taken from the same branch.
Upvotes: 1
Reputation: 169
If I understand correctly, you have a locally modified file that you have not added or committed. If you run git status
you should expect to see
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: foo/file1.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
If that is the case, git is actually giving you a hint in the status output.
All you need to do is git checkout -- foo/file1.txt
. This will throw out the changes you made locally, and give you back the checked in contents. Since git told you that you are up to date with the remote when you did git pull
, this should be the same version as the remote has.
Hope this helps.
Upvotes: 8