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
0
votes
2 answers

Git remove only push last local commit

I have made a bunch of changes on my local git version of a Rails project that I don't want to lose, however in doing so, I accidentally created a vendor/bundle folder in Git. I realized as soon as I committed that I did this and did a git rm for…
creativereason
  • 1,524
  • 1
  • 11
  • 20
0
votes
1 answer

How do I git out of this mess with a git submodule?

I've got a git repo with Wordpress as a submodule. I was trying to update Wordpress and really screwed things up. I just want to get all of the code from the 3.7.1 tag in the remote repository, but this doesn't work; git fetch --tags git checkout…
Jo Sprague
  • 16,523
  • 10
  • 42
  • 62
0
votes
2 answers

Do dangling git add blobs get pushed to master repository?

We can recover files, which were once added (but not committed) and later removed using git reset --hard. See Recovering added file after doing git reset --hard HEAD^ When we push in our changes to some upstream repository, Are these blobs also…
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
0
votes
1 answer

Reverting a git pull that's already been pushed

I'm not sure if this is a duplicate or not as it's kind of a one off scenario: I have a "beta" branch, and started a new "refactor" branch. I did a bunch of code in "refactor" branch. I pulled latest changes from beta into refactor (git checkout…
streetlogics
  • 4,640
  • 33
  • 33
0
votes
2 answers

After doing `git commit` git tells me there is nothing to commit

I am on my gh-pages branch and when I $ git add $ git commit -m "" I see # On branch gh-pages nothing to commit, working directory clean Then I will do and see the following $ git stage Nothing specified, nothing added. Maybe you…
user883807
0
votes
1 answer

When running git reset --hard, the staged changes persist. Same goes for git checkout and git stash + git stash drop. What's going on?

So here's some background: I'm trying to move a repository from Mercurial to git using hg-fast-export and when I do the last step (git checkout HEAD) there are still changes that persist in the repository. Specifically, it says that there are 4…
Caustic
  • 475
  • 3
  • 14
0
votes
3 answers

How badly did I hose my git repo?

My project has a bare repo setup on the server. I'm currently on branch 0.9/develop. I merged 0.9/develop with a branch that another developer was working on. It turns out that it would be way more work to fix his code than to obliterate his changes…
Ben Harold
  • 6,242
  • 6
  • 47
  • 71
0
votes
1 answer

Make earlier version in git the latest version?

What should I do in git if I've found myself wanting to return to an earlier version in my history, and commence editing from there? (i.e., make some earlier version to the forefront and start committing/pushing to it)? Doing git reset --hard HEAD~1…
limp_chimp
  • 13,475
  • 17
  • 66
  • 105
0
votes
1 answer

Getting back to an erroneous git reset

Say I'm working on a project and I'm making various commits as I go along A - B - C - D - E And I realise that I made a mistake and need to do git reset to go back to version C. So I then carry on making commits like this: C - D2 - E2 - F2 - G2…
Lars
  • 7,908
  • 11
  • 52
  • 70
0
votes
1 answer

Undoing my working directory preserving my commit

This could be a very simple question. I commited my work, then I launched a find and replace script but I want to undo it, so to let my work go down to the actual commit. What is the right command to do that : I know about git reset soft/hard or git…
user1611830
  • 4,749
  • 10
  • 52
  • 89
0
votes
1 answer

GIT Development reset with clones

My current setup is I have a Prime repo (working directory), Hub repo (bare, developers push and pull from), Clones (for developers). The Prime and Hub repos are kept in sync via various hooks. There was an issue and I wanted to perform a reset to a…
neolaser
  • 6,722
  • 18
  • 57
  • 90
0
votes
1 answer

Git recover stashed changes after merge --no-ff

I frequently use "git stash" and "git stash pop" to save and restore changes in my working tree. This is what I did and my previous uncommitted changes now are gone. git stash -u git checkout master git pull --rebase git checkout dev git merge…
user43092
  • 363
  • 1
  • 3
  • 7
-1
votes
2 answers

What is the difference between "git reset --hard HEAD~1" and "git checkout ."?

I'm currently learning git, and I have issue what exactly do these commands do? git reset --hard HEAD~1 git checkout . What's the difference between the two? They both permanently delete the last commit, as I understand. I think that there is a…
-1
votes
4 answers

Git: I can't seem to reset my local main to origin/main

I want to do something very simple: update my local main to the remote one. Except it seems HEAD and origin/main are somehow pointing to an old commit. I want to fast forward HEAD and can only seem to find posts about rewinding. On branch main, when…
-1
votes
1 answer

Undo git pull --rebase

Sorry for bothering everyone! Please help. I wrongly used the git rebase --hard and overwrite all local files. Then I use git reflog and git reset --hard but did not find the former version! I searched for many questions but it seems that they only…
stander Qiu
  • 122
  • 10