Showing posts with label git reset. Show all posts
Showing posts with label git reset. Show all posts

Saturday, 16 October 2010

Beginner's guide to : Remove uncommitted changes in Git

Our case is, somewhat below :

(1) Remove changes on specific file.
(2) Remove all changes we made.

What we want is to get into the previous state, before we started to tinker with it.
We need to run this below for case (1) :

$ git checkout filename

And here below, to remove EVERY changes made :

$ git reset --hard HEAD || $ git reset --hard

(tips HEAD = last, HEAD^ = next to last, HEAD~2 = last - 2, and so on)

Sunday, 19 September 2010

Beginner's guide to : Unstaging committed files on Git

For example, we have this below :

$ git status
# On branch tryone
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
# new file:   config/database.yml
# new file:   log/development.log
# new file:   log/production.log
# new file:   log/server.log
# new file:   log/test.log

and we have a change of mind about committing log/test.log, we want it off the list, we don't want the changes on it to be committed further more to be saved on the remote repository. So what we need to do is to run this line below:

$ git reset log/test.log

Voila! it's done! check it out with git status and you'll have log/test.log no longer on the list.

Btw, those mentioned above works on removing single added file, or, if you're in the mood of listing the files (after HEAD) you can do multiple remove, but if removing all added files (uncommitted ones) do this below instead :

$ git reset

'Enjoy!