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

Synopsis

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

Options

--mixed
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.

--soft
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.

--hard
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.

--merge
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.

--keep
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>
Commit to make the current HEAD. If not given defaults to HEAD.

See also

Reference

$ git reset --help
509 questions
8
votes
1 answer

Squashing commits after they are pushed

Imagine a git repository with the following commits: Fixed issue 3 123eabc Fixed issue 2 (part 2) fa23b79 Fixed issue 2 (part 1) 7bea5cc Fixed issue 1 0d229f4 These are all pushed to remote master already. Is…
Merik
  • 2,767
  • 6
  • 25
  • 41
7
votes
2 answers

Git: How to Undo commit *and* revert to last branch

Uh oh... I mistakenly committed a pretty complex change (including subdirectory and files renames) without really knowing what I am doing (or what Git would be doing). I now want to undo everything such that: commit is completely reversed (as if it…
WinWin
  • 7,493
  • 10
  • 44
  • 53
7
votes
5 answers

BUG: unpack-trees.c:699: pos must point at the first entry in this directory

I tried to soft reset my branch to remove a directory I had accidentally pushed to GitHub. After the soft reset I was still getting the following error: fatal: Unable to create…
7
votes
2 answers

Why does git checkout not delete new files?

Suppose I create (but do not commit) a file file.txt, and then type git checkout HEAD or git checkout HEAD .. I thought git checkout basically overwrote your current working files with the snapshot at the commit you give it, so I would have thought…
Jack M
  • 4,769
  • 6
  • 43
  • 67
7
votes
3 answers

Revert staged changes, keep unstaged changes

I have some staged and some unstaged changes in git, as well as some untracked files. I would like to keep the unstaged changes and untracked files, and discard the staged changes. Whats the easiest way to do this on the command line?
Jan Rüegg
  • 9,587
  • 8
  • 63
  • 105
7
votes
3 answers

How I can store some local changes that survives git reset --hard

I have some local changes (not in separate files so .gitignore doesn't work) that I don't want to commit. I do git reset --hard sometimes after commit to clear occasional changes but obiously I also lose my useful changes that I want to…
freemanoid
  • 14,592
  • 6
  • 54
  • 77
6
votes
1 answer

How to revert a file to a previous version without overwriting current changes?

I'm having a problem trying to revert a file to a previous commit, I know I can use git checkout to revert a single file but the problem is I have changes in that file I'd like to keep so I was wondering how to do some sort of "merge" between a…
Javier Villanueva
  • 3,886
  • 13
  • 48
  • 80
6
votes
4 answers

How do I save work in progress without using git-stash?

I have a git directory with this situation: ProgSoul@PROGSOUL-LENOVO:~/esercizio3_2$ git status Sul branch master Changes to be committed: (use "git reset HEAD ..." to unstage) modified: A Changes not staged for commit: (use…
6
votes
2 answers

What exactly is the difference between all the Git Reset modes?

I'm trying to add succinct summaries of Git's reset modes for the Git-Savvy Sublime extension. It's hard! I have this: mixed (default): update index soft: move branch pointer only hard: update index & working dir, discard local changes merge:…
Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
6
votes
3 answers

Git reset --hard not working as expected

I am trying to inspect the history of a repository. I stopped at a point where I want to return the repository back to a specific commit. I searched and I did git reset --hard 12345 I got the message that HEAD is now at 12345. I opened the folder…
Arwa
  • 63
  • 1
  • 1
  • 4
6
votes
1 answer

Git commit lost after reset --hard. Not found by fsck, not in reflog

I wanted to clear my working directory of some uncommitted files, but accidentally ran git reset --hard. I realized that I had lost the previous (un-pushed) commit, so I ran git reset --hard ORIG_HEAD. This did not get me to my lost commit. I ran…
Niel Thiart
  • 628
  • 7
  • 13
6
votes
3 answers

Revert pushed branch to a concrete commit

I have merged a dev branch (with constant, sometimes unstable changes) to our master branch (where we store the released, stable code). I want to restore the master branch to the state it was before like the merge with the dev branch had never…
Carlos Campderrós
  • 22,354
  • 11
  • 51
  • 57
5
votes
1 answer

Is 'git reset --soft' a no-op command?

The documentation states that leveraging the --soft option "...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…
nulltoken
  • 64,429
  • 20
  • 138
  • 130
5
votes
3 answers

Discard all uncommitted changes, modified files, added files and non-added

What is the best way to discard uncommitted changes with Git. I read this, but want to fully understand what each step is doing. git undo all uncommitted or unsaved changes git reset "This will unstage all files you might have staged with git…
user2012677
  • 5,465
  • 6
  • 51
  • 113
5
votes
2 answers

Why can't I rollback to a point when I use Revert in Github in Android Studio 3.3.1?

I commit and push my code three times, they are Submit 1, Submit 2 and Submit 3. I hope to rollback my code to the point Submit 2 and push them to remote repository. So I do Revert operation on the point Submit 2 (See the image Do Revert), a Files…
HelloCW
  • 843
  • 22
  • 125
  • 310