Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recovering a git reset --soft

Tags:

git

reset

I modified some files in my branch and did a

git add --all

But this added some files that I didn't intend to add for the commit.

So I did a

git reset --soft HEAD~2 (instead of doing git reset HEAD)

But the previous commit was made by someone else and it caused a lot of files to be in modified/added/deleted status. Is there a way to get back to a stage where the only changes I see are the files added/modified by me? Since I didnt make an actual commit, is there a way to move my head back to master without blowing away my changes? git pull is causing merge conflicts as I didn't actually commit my changes.

Thanks!

like image 581
kriver Avatar asked Jan 03 '11 23:01

kriver


People also ask

How do I reset a Git file?

Git Reset 1 Reset a file or set of files. The following command lets you selectively choose chunks of content and revert or unstage it. 2 Unstage a file. The changes you made will still be in the file, this command just removes that file from your staging area. 3 Reset a branch to a prior commit. ... 4 Important Note About Hard Resets. ...

How does a'soft reset'work in Git?

We have executed a 'soft reset'. Examining the repo state with git status and git ls-files shows that nothing has changed. This is expected behavior. A soft reset will only reset the Commit History. By default, git reset is invoked with HEAD as the target commit.

What does Git reset --hard and --soft do?

lastly, git reset --hard wipes everything out including your local changes. The ~ after head tells you how many commits to go to from the top. You can use git reset --soft to change the version you want to have as parent for the changes you have in your index and working tree.

How to restore a deleted commit in Git?

Suppose that you have run git reset HEAD~1 by mistake, which has deleted the latest commit from your local branch and, now, you want to restore that commit. Below, we will demonstrate how to do it. Git keeps a log of all reference updates (e.g., checkout, reset, commit, merge). Run the git reflog command to view them:


2 Answers

For future reference, you can review the commits that your behavior causes or leaves behind by calling git reflog , which will include commits that are no longer in your working tree.

like image 196
Kzqai Avatar answered Oct 27 '22 13:10

Kzqai


Just do git reset master. This will only update the index and what HEAD points to. It will not modify your work tree files.

like image 37
Dan Moulding Avatar answered Oct 27 '22 14:10

Dan Moulding