Reputation: 4742
I am programming. I add beautiful code and commit and push it to my repo like:
git add *
git commit
//writes message
git push unfuddle master
Now i go in and screw everything up. I have not issued a git command since I push the beauty. How do i make my local files go back to what was committed?
git pull
says my local repo is "up to date"
git checkout
spams out my screen and doesnt seem to change anything.
To be clear: I am not trying to modify my remote repo, just get my local repo to look like the server.
My current solution is to delete the folder and reclone the repo. That can't be right.
Upvotes: 35
Views: 42593
Reputation: 181
git checkout branchname
git reset --hard c4e0424
git push origin +branchname
You can use --soft instead of --hard
--hard
you will LOSE your changes
--soft
leave your changed files of commit
Upvotes: 0
Reputation: 129584
UPDATE:
The best way to do this is to
git stash -u
Do not
git reset --hard HEAD
it is an operation that cannot be undone and you can truly nuke your work unless you're using time machine on a Mac or the new backup service on Windows 8. Linux may have a scheme like that although I don't use one.
If you also want ignored files nuked, you can
git clean -xdf
Upvotes: 23
Reputation: 133008
Since you haven't committed anything yet, the following command will reset your modified files:
git checkout .
Upvotes: 8
Reputation: 72557
git pull says my local repo is "up to date"
git pull
is telling you your repository is up to date because your local repository and your remote repository both point to the same HEAD (the last commit). This is due to your git push
, which synced the remote with your local repository.
Git doesn't compare the changes that haven't been committed to the remote branch when it decides what to pull; thus, from Gits point of view, your local and remote repositories are at the same point in time, even though your local repository has unstaged changes (changes that you have not git add
ed).
There's a nice diagram on the bottom of this page which shows you how the process works - you make some changes, stage them (by running git add
), and then finally commit them to the repository (through the creatively named git commit
).
To be clear: I am not trying to modify my remote repo, just get my local repo to look like the server.
Others have pointed out the methods to do this:
git reset --hard HEAD
(reset the index [staged files] and the working tree [unstaged files] to the last commit), but it's worth having an understanding of what you're trying to achieve - if I'd known how git was tracking my files the first time I messed up my working tree, I'd have saved hours of fretting.
Upvotes: 3
Reputation: 2461
If you does not have committed anything, you can simply do a $ git reset --hard
. If you have committed some stuff, you can do a git reset --hard origin/master
to go back to the version that is on the remote.
Upvotes: 1