Gangmax Blog

How to Discard the Local Changes of Git

From here.

If you already stage you local changes(which means you run the “git add xxx” already), you should reset the buffer zone first:

1
2
3
git reset HEAD hello.html
# 'HEAD' is the branch name you're working on;
# 'hello.html' is the file you changed, you can run "git status" to get the listof the local changed files.

Now the buffer zone of the branch you’re working on is reset, but you local file still has the changes. Use the “checkout” command to discard your local file changes(If you didn’t stage your local changes as step 1 described, just do this step):

1
git checkout hello.html

Now you local changes is totally discarded.

Comments