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
1 answer

git reset HEAD~1 --soft made my staged files list full of files I haven't touched

I accidentally committed two files to develop branch instead of my feature branch, but fortunately did not push them yet. So I read how to undo that, so that I'll keep my changes and found the command git reset HEAD~1 --soft After running that my…
Steve Waters
  • 3,348
  • 9
  • 54
  • 94
0
votes
2 answers

How to fix "unable to unlink 'filename': Resource busy

When I'm trying to revert some of my local changes it says "error: unable to unlink old 'filename': Resource busy" I already tried to stash the changes, use git reset --hard but nothing works.
0
votes
1 answer

Checkout remote branch in a failsafe way, throwing local changes away?

Common recommendations to reset your working copy (master branch) to the state of the upstream branch seem to be: git checkout master git fetch git reset --hard origin/master and git checkout master git reset --hard git pull Or with detaching the…
CodeManX
  • 11,159
  • 5
  • 49
  • 70
0
votes
1 answer

git push won't push latest changes after I do a git reset

I mistakenly did a git reset --hard on my repo thinking it behaved differently than it does, so then I did git reflogs and another git reset to restore the changes I accidentally deleted. Now my local repo is fine but for some reason when I push to…
ekolis
  • 6,270
  • 12
  • 50
  • 101
0
votes
2 answers

Reset master to HEAD^ instead of HEAD and committed, how to recover?

This is the state of the local branch before I did anything: B<-A... And this is the remote: B<-A... I was running git add -A on the repository and observed that it's taking too long. Turned out I hadn't ignored directory v3 with large development…
Paghillect
  • 822
  • 1
  • 11
  • 30
0
votes
1 answer

Egit: how to make a reset of a subfolder?

I want to make in EGit the same operation performed by the "Revert" command in Subversive on a single folder. Basically, the expected result is a "reset --hard" of the chosen folder, removing all not committed changes, without make it for the other…
Alessandro C
  • 3,310
  • 9
  • 46
  • 82
0
votes
0 answers

How to recover modified files with git checkout?

I wanted to check if my new changes to code were compatible with existing database, thus I tried to create a new branch from HEAD of remote ORIGIN. I ran exactly the following code : git checkout -b test origin/master Till this time, my modified…
pandafy
  • 184
  • 13
0
votes
0 answers

Undo my merge commit that has cause work lost on branch I was merging to

This morning I did a merge commit of my feature branch into the main dev branch but when doing so I forgot to update the dev branch that had several commits and merge commits from other people on it. So when I did my merge commit I was asked if I…
John Cogan
  • 1,034
  • 4
  • 16
  • 39
0
votes
2 answers

How to unsquash pushed commit to bitbucket

I have squashed 7 commits (using git rebase -i HEAD~7) into a single commit and pushed the changes to bitbucket server. Now, I realized I need to push the 7 commits in original state. I tried git reflog and git reset --hard HEAD@{7} But can only see…
Saurabh
  • 975
  • 2
  • 12
  • 27
0
votes
2 answers

How to permanently undo recent commits from git remote but keep it in my local?

I made a git repo (only a master branch) with one remote and one local. There are no other users who have cloned it but the remote path can be cloned by a few users. My local clone is at commit #17 and I have pushed up til commit #12 to the remote.…
Palace Chan
  • 8,845
  • 11
  • 41
  • 93
0
votes
1 answer

git reset --hard will make source code lost permanently when the file is added to the staging zone but not in repository

I add some new files to index git add . then reset git reset --hard git deleted these files in my working tree, there are not in repository previously, they are all lost. I lost all my data.
yuanjianpeng
  • 318
  • 2
  • 11
0
votes
1 answer

How to revert git after hard reset

I am trying to revert hard reset in my local branch I was trying to commit changes to github repository. But it said your current branch is behind. I found hard reset option. I did hard reset after i pulled and pushed files but it changed all files…
0
votes
0 answers

Overwrite local repository with remote

I would like to "self-update" my php app with git. The app should fetch the latest code from the remote repository (github) and overwrite the local code. It should do the following: Fetch the latest code from remote (only master branch) overwrite…
David
  • 1
  • 1
0
votes
3 answers

git reset --soft "HEAD^6" what does it means?

I ran git reset --soft "HEAD^6" by mistake on my local repo after that I ran git reset --soft "HEAD^" Now i can find more than 100 file with local changes What git reset --soft "HEAD^6" does it mean ? Edit: for those who will ask why i did that, it…
Melad Basilius
  • 3,847
  • 10
  • 44
  • 81
0
votes
2 answers

How can I restore files deleted using git hard reset?

I accidentally used git reset -hard on my files in server and it had files which are not added or committed using git add or git commit. How can I restore those files which are not staged? Please help.