Questions tagged [git-reset]

Sets the current Git repo head to a specified commit and optionally resets the index and working tree to match.

If you've made a mistake in the current working tree, and haven't committed, you can revert the entire working tree to the last commit state with the following:

$ git reset --hard HEAD


git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]
git reset [-q] [<commit>] [--] <paths>...
git reset --patch [<commit>] [--] [<paths>...]


Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.

Does not touch the index file nor the working tree at all, but requires them to be in a good order. This leaves all your changed files "Changes to be committed", as git status would put it.

Matches the working tree and index to that of the tree being switched to. Any changes to tracked files in the working tree since <commit> are lost.

Resets the index to match the tree recorded by the named commit, and updates the files that are different between the named commit and the current commit in the working tree.

Reset the index to the given commit, keeping local changes in the working tree since the current commit, while updating working tree files without local changes to what appears in the given commit. If a file that is different between the current commit and the given commit has local changes, reset is aborted.

-p, --patch
Interactively select hunks in the difference between the index and <commit> (defaults to HEAD). The chosen hunks are applied in reverse to the index. This means that git reset -p is the opposite of git add -p (see ).

-q, --quiet
Be quiet, only report errors.

Commit to make the current HEAD. If not given defaults to HEAD.

See also


$ git reset --help
509 questions
41 answers

How do I revert a Git repository to a previous commit?

How do I revert from my current state to a snapshot made on a certain commit? If I do git log, then I get the following output: $ git log commit a867b4af366350be2e7c21b8de9cc6504678a61b` Author: Me Date: Thu Nov 4 18:59:41 2010…
Crazy Serb
  • 76,330
  • 8
  • 35
  • 47
37 answers

How do I delete a commit from a branch?

How do I delete a commit from my branch history? Should I use git reset --hard HEAD?
  • 154,439
  • 43
  • 83
  • 99
13 answers

Move existing, uncommitted work to a new branch in Git

I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch. How do I move the existing uncommitted changes to a new branch and reset my current one? I want to reset my current branch while…
Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173
21 answers

How can I remove a commit on GitHub?

I "accidentally" pushed a commit to GitHub. Is it possible to remove this commit? I want to revert my GitHub repository as it was before this commit.
  • 74,396
  • 19
  • 43
  • 46
13 answers

Can I delete a git commit but keep the changes?

In one of my development branches, I made some changes to my codebase. Before I was able to complete the features I was working on, I had to switch my current branch to master to demo some features. But just using a "git checkout master" preserved…
  • 22,575
  • 8
  • 27
  • 25
20 answers

How can I undo git reset --hard HEAD~1?

Is it possible to undo the changes caused by the following command? If so, how? git reset --hard HEAD~1
Paul Wicks
  • 62,960
  • 55
  • 119
  • 146
14 answers

Why there are two ways to unstage a file in Git?

Sometimes git suggests git rm --cached to unstage a file, sometimes git reset HEAD file. When should I use which? D:\code\gt2>git init Initialized empty Git repository in D:/code/gt2/.git/ D:\code\gt2>touch a D:\code\gt2>git status # On branch…
  • 17,020
  • 5
  • 23
  • 28
8 answers

How to uncommit my last commit in Git

How can I uncommit my last commit in git? Is it git reset --hard HEAD or git reset --hard HEAD^ ?
  • 13,881
  • 3
  • 18
  • 9
16 answers

git undo all uncommitted or unsaved changes

I'm trying to undo all changes since my last commit. I tried git reset --hard and git reset --hard HEAD after viewing this post. I responds with head is now at 18c3773... but when I look at my local source all the files are still there. What am I…
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188
2 answers

How do I use 'git reset --hard HEAD' to revert to a previous commit?

I know that Git tracks changes I make to my application, and holds on to them until I commit the changes. To revert to a previous commit, I used: $ git reset --hard HEAD HEAD is now at 820f417 micro How do I then revert the files on my hard drive…
Brian McDonough
  • 13,829
  • 4
  • 19
  • 23
14 answers

How can I revert uncommitted changes including files and folders?

Is there a Git command to revert all uncommitted changes in a working tree and index and to also remove newly created files and folders?
  • 30,529
  • 42
  • 121
  • 191
4 answers

Undo a particular commit in Git that's been pushed to remote repos

What is the simplest way to undo a particular commit that is: not in the head or HEAD Has been pushed to the remote. Because if it is not the latest commit, git reset HEAD doesn't work. And because it has been pushed to a remote, git rebase…
  • 84,407
  • 47
  • 135
  • 168
8 answers

How to cancel a local git commit?

My issue is I have changed a file e.g.: README, added a new line 'this for my testing line' and saved the file, then I issued the following commands: git status # On branch master # Changed but not updated: # (use "git add ..." to update…
Amal Kumar S
  • 15,555
  • 19
  • 56
  • 88
8 answers

What's the difference between "git reset" and "git checkout"?

I've always thought of git reset and git checkout as the same, in the sense that both bring the project back to a specific commit. However, I feel they can't be exactly the same, as that would be redundant. What is the actual difference between the…
  • 182,215
  • 215
  • 566
  • 871
8 answers

Git: can't undo local changes (error: path ... is unmerged)

I have following working tree state $ git status foo/bar.txt # On branch master # Unmerged paths: # (use "git reset HEAD ..." to unstage) # (use "git add/rm ..." as appropriate to mark resolution) # # deleted by us: …
  • 4,770
  • 2
  • 16
  • 8
2 3
33 34