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
5
votes
4 answers

Recover from Git reset --hard in Eclipse

I accidentally did something to my git repo and I don't know if I can save my project at this point... I had a bunch of changes that I made. Then I wanted to delete my last commit so that I could make this new commit instead. I forgot to do git…
brienna
  • 1,415
  • 1
  • 18
  • 45
5
votes
1 answer

After a git reset, unreachable commit not removed

I have a small repo that has a couple of commits: * a0fc4f8 (HEAD -> testbranch) added file.txt * e6e6a8b (master) hello world now * f308f53 Made it echo * f705657 Added hello * 08a2de3 (tag: initial) initial Also: $ git status On…
Jim
  • 18,826
  • 34
  • 135
  • 254
5
votes
1 answer

RStudio revert button seems to act like Git reset

I am quite new to RStudio and Git, so I would like to make sure that I understand correctly what I am doing. The Git documentation says that git revert creates a new commit. When I press the RStudio revert button, no new commit is created, it just…
Christoph
  • 6,841
  • 4
  • 37
  • 89
5
votes
4 answers

fatal: ambiguous argument '–hard': unknown revision or path not in the working tree. Use '--' to separate paths from revisions

I am trying to execute the below git commnand: git reset –hard DI_BINARY_REPOSITORY_IMX6_LINUX_14.4C504.2 but I am getting the following error: fatal: ambiguous argument '–hard': unknown revision or path not in the working tree. Use '--' to…
5
votes
2 answers

Undo git reset --hard after git stash pop

I had some changes in the stash that I attempted to recover using git stash pop. There were some merge conflicts, and rather than resolving them, I decided to just reset it. Unfortunately, in a moment of stupidity, I did a git reset --hard, and now…
eirikir
  • 3,802
  • 3
  • 21
  • 39
5
votes
1 answer

why do git reset commit + git push cause tip of current branch to go behind remote?

I wanted to undo a couple minor changes on my repo. I decided to go back two commits, and did git reset --hard and git push -f Everything went through fine. But when I pushed to heroku, I got an error about how some refs weren't pushed,…
calyxofheld
  • 1,538
  • 3
  • 24
  • 62
5
votes
1 answer

Generic git reset to default upstream HEAD

Is there a syntax to reset to the current branch's default upstream HEAD? Something like: git checkout mybranch git reset --hard origin/mybranch where origin/mybranch can be generic for the current branch's upstream HEAD?
Chris
  • 4,594
  • 4
  • 29
  • 39
5
votes
3 answers

How do I change a commit message after a 'git-pull' auto-merge?

Occasionally, my collaborators will "panic" when there is an automatic merge generated as the result a git-pull, and just accept the default commit message. Before this commit gets pushed, I want to be sure the message gets fixed, but --amend seems…
orome
  • 45,163
  • 57
  • 202
  • 418
4
votes
2 answers

What is the difference between `git rebase -i HEAD~N` and `git reset --soft HEAD~N`?

We can squash the last N commits in Git. As I understand, we can squash last N commits using git rebase -i HEAD~N or git reset --soft HEAD~N. In the answers for this question (Squash my last X commits together using Git) most upvoted answer advices…
alper
  • 2,919
  • 9
  • 53
  • 102
4
votes
2 answers

How do I `git reset` in a worktree?

I've noticed that if I try to git reset on a secondary worktree, it resets based on the primary worktree. Suppose I have master (d) checked out on my normal repo, and have feature (f) in my separate worktree. If I do git reset --hard head~1 I end…
Ben Catterall
  • 401
  • 3
  • 14
4
votes
1 answer

GIT Pull deleted my commit

After git pull I have done git reset hard to undo the merge with commit id before merge.Somehow my entire commit is gone and I cant the see the commit in history also. But I have the commit id , on git show command I can see my changes. How can I…
Sirish
  • 9,183
  • 22
  • 72
  • 107
4
votes
1 answer

Get back to latest commit after soft reset

I know there are people having this asked already, but none provided a solution that helped me. I use GitKraken, which obviously has no integrated functionality for checking out older commits in the history (I had to test a bit, no changes made). I…
SharpShade
  • 1,761
  • 2
  • 32
  • 45
4
votes
1 answer

Does the command "git reset --hard " remove commit history in another branch?

Let's say I made a, b, c, d commits so far. I'm currently in d and I want to go back to a. a and d are in master branch. b and c are temp branch. In this case, if I run git reset --hard , will I lose the commit b and c because they are…
Jay P.
  • 2,420
  • 6
  • 36
  • 71
4
votes
2 answers

Why does `git reset --hard HEAD~X` leave untracked files behind?

From git reset --hard HEAD leaves untracked files behind: When I run git reset --hard HEAD, it's supposed to reset to a pristine version of what you pulled, as I understand it. Unfortunately, it leaves files lying around, as a git status shows…
Michael Haar
  • 671
  • 6
  • 14
4
votes
1 answer

After reverting to an old commit, I can't go back to the most recent commit

I reverted my repo to an old commit, to see if a bug happens there. I thought I did it with: git checkout the_rev_number . But judging by what's happening, I may have forgot the period at the end. Now git log shows the same rev (as the one I…
Stefan Monov
  • 11,332
  • 10
  • 63
  • 120