Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recover last commit after git hard reset?

Tags:

git

Can I recover the following commit after a hard reset?

Steps:

1) $ (master) // ....made a bunch of changes to files thinking I was working on a branch
2) $ git checkout -b 001-branch  // copy changes to a branch to work with
3) $ (001-branch) // make some more changes to files
4) $ (001-branch) git commit -a -m 'added and changed stuff'
// at this point I was just going to pull force master to latest then rebase my 001-branch off of original master (not the stuff I had modified)
5) $ (001-branch) git checkout master
6) $ (master) git reset --hard HEAD
7) $ (master) git pull
8) $ (master) git checkout 001-branch // go back to my branch and rebase my changes
9) $ (001-branch) // oops...my changes were all kiboshed and I don't see the commit I did per git lg

Any way out of this mess to recover my changes?

like image 634
genxgeek Avatar asked Nov 11 '13 03:11

genxgeek


People also ask

Can you undo hard reset git?

You can safely undo your local changes using the reset command. However, if you want to undo changes you have committed to a remote repository, always use the revert command instead.

Does git reset hard remove commit history?

Using the git reset --hard option resets the current branch tip, and also deletes any changes in the working directory and staging area. Therefore, it resets index entries to the state of the specified commit.


1 Answers

To see all the changes made to your 001-branch, you can do git reflog 001-branch, however, chances are what you think you did in 001-branch maybe you did another branch, so you probably need to look into all the changes with git reflog.

like image 53
FelipeC Avatar answered Oct 07 '22 18:10

FelipeC