Reputation: 33880
I have the master branch of my repository checked out. It has the following 4 files.
While reading each of these files, I ended up making small but unintentional changes to Two.txt and Four.txt. These changes are of the nature of adding line breaks or spaces or removing some of them. It wouldn't hurt to check them in but I'd rather not.
I am still in the master branch and I'd like to undo the changes I made to these two files.
When I do:
$ git status
It reads:
Changes not staged for commit.
Two.txt
Four.txt
I understand that unless I git add them, the changes to these files will be un-tracked and hence will not be considered for commits.
But I'd still like to rollback changes I made to these files and get the real version that I downloaded.
I did:
$ git checkout
But that didn't make the red go away.
Then I did:
$ git pull
So it would fetch and merge from the remote master into my local master but that didn't overwrite the changes I made to Two.txt and Four.txt.
How do I overwrite the changes I made to Two.txt and Four.txt with the original content that the remote repo's master had?
Upvotes: 0
Views: 58
Reputation: 5084
To undo changes either you use checkout
git checkout -- Two.txt Four.txt
Or if your workspace is clean and doesn't contain any new changes that you don't want to loose, in this case you can use reset --hard
that will force the commit you tell it
# I want the version of HEAD
git reset --hard HEAD
Be careful, this will apply the version of HEAD
to all the files of your project
Another helpful command stash
# To move changes from the workspace
git stash
# Delete that stash
git stash pop
Upvotes: 1
Reputation: 16763
If you want to reset all the changes you made
git checkout -f
In case you want to checkout only unstaged changes instead
git checkout -- .
Upvotes: 2