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

Unclear Documentation of the git reset command

Taken from the docs: git reset : After running git reset to update the index entry, you can use git-checkout[1] to check the contents out of the index to the working tree. Alternatively, using git-checkout[1] and specifying a commit, you…
clickMe
  • 993
  • 11
  • 33
0
votes
1 answer

Unable to push reverted file to repository after git reset

Note - I am new to understanding the git reset command, so I am not sure if it is the right command for what I want to do, which is very simple. I wanted to undo the changes made in the last git push. So, I ran the following reset command to go back…
Sandeepan Nath
  • 9,966
  • 17
  • 86
  • 144
0
votes
2 answers

un-deleting file after running "git reset" after running "git rm"

I accidentally ran git rm file to undo that I ran git reset HEAD which didn't restore the file, so then I ran git reset HEAD~1 which didn't seem to restore the file either (this should be easy...) Now I see this: Unstaged changes after reset: M …
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
0
votes
1 answer

How can I reset hard all branches in git

How do I reset my all local branches, one time to be just like the branches in the remote repository? I have 42 branches in my local repository, but I have just 21 branches in my remote repository. I don't need the other branches, I just need the 21…
Oscar
  • 5
  • 7
0
votes
1 answer

Git reset or checkout specific file using Grunt

I have a grunt process that creates a deployment package, and it involves making changes to files that need to be present for deployment, but not checked into source. I'm looking for an automated way to either reset individual files or checkout…
jlewkovich
  • 2,725
  • 2
  • 35
  • 49
0
votes
2 answers

Will doing a hard reset to an old commit on new branch will reset the master as well?

I want to see what the design looked like at a previous commit so I want to checkout to a new branch and then revert/hard reset to that older commit. I am quite new to commit and wouldn't like to break anything by randomly experimenting so will…
dkjain
  • 831
  • 1
  • 9
  • 36
0
votes
2 answers

git reset remote head

My colleague has pushed some commits to our working branch by mistake and now I want to rollback to a previous commit both locally and remotely. I use reset --hard to the selected commit, the HEAD in my local branch moves to the selected commit and…
Dimitra
  • 1
  • 1
  • 3
0
votes
1 answer

Is the full path required to unstage a file in GIT if am currenlty under a sub-directory?

Repo: mergetest $pwd /gitvobs/mergetest/apple $git status On branch br1 Changed but not updated: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) **modified: inside** $git…
Senthil A Kumar
  • 10,306
  • 15
  • 44
  • 55
0
votes
1 answer

Do a git reset only if other branches refer to the commits

Is there any way to remove a couple of commits from a branch only if a different branch refers to the commits? For example, if I did the following commits: ABC-1: Add views for feature ABC-1 ABC-1: Add controller action for feature ABC-1 and then I…
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
0
votes
1 answer

How to revert/reset local master to HEAD?

I'm trying to push a older commit to heroku/master, but if I'm not mistaken git push pushes the local master to the remote repo. So I'm trying to get my local master to match my HEAD. I'm trying to do it without losing the commits I made so I maybe…
Edito
  • 3,030
  • 13
  • 35
  • 67
0
votes
1 answer

git checkout commit and then making it the base

I'm on a branch called A.. the branch A has two commits, with the following codes: commit1 and commit2 where the most recent is commit2. i just noticed i want to go back to commit1 because in commit2 I deleted a file I needed and i wrote some…
valerio0999
  • 11,458
  • 7
  • 28
  • 56
0
votes
0 answers

How to restore a git reset --hard HEAD@{1}

I do a git reset --hard HEAD@{1} But I removed some things wrongly. I try solve it git fsck −−lost-found But it no found the "revert" Thanks...
user3854612
  • 127
  • 1
  • 1
  • 7
0
votes
0 answers

Git revert pull doesn't work

I did a mistake this morning and pull my master on my branch. I try reset to HEAD@{13} but doesn't work, my work is still missing :s Thanks for your futur help,
0
votes
1 answer

Undo git reset --hard

I intended to git reset --hard to the last commit I made but I accidentally went back to the commit before that. Is there anyway to undo this. This was the sequence of events: 1. I pulled from a common repo and made some changes and committed them…
Hitch
  • 17
  • 1
  • 6
0
votes
1 answer

Undo all files within a folder in git

I searched and found many link which talks about un-doing your uncommited changes with respect to specific file: git reset git reset --hard git checkout -- file git checkout branchname^ filename but I want to undo changes for all the files I…
SharpCoder
  • 18,279
  • 43
  • 153
  • 249