Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Undo "Reset current branch to this commit"

lmiguelmh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 24, 2014

I am new with this tool, I've never used GIT neither.

I had a merge conflict... so I was messing with SourceTree and I did a hard "reset current branch to this commit" and ended with my code resetted and all my changes lost.

image2014-11-24 23:23:42.png

Is there a way that I could revert or undo this?

Thanks a lot.

2 answers

10 votes
TimP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 24, 2014

Hi Im,

Don't panic! Losing work sucks, but there absolutely is a way to recover any previously committed changes smile Fortunately git is pretty good about not losing things, even if you've done a hard reset.

You'll need to use a git built-in tool called the reflog. Sourcetree doesn't yet support it, so you'll need to open your repository from the command line (and install git, if you haven't already).

Once you're in your repository, run the command git reflog to show a list of ref updates that you've made to your local repository. If the "reset" is the last change you made, it should look something like this:

$ git reflog
62eda16 HEAD@{0}: reset: moving to 62eda16
badcafe HEAD@{1}: blah blah blah
abc1234 HEAD@{2}: something something

You'll want to reset your branch (again) to the commit that it was pointing at before you ran the reset command. In the above example reflog output, this would be HEAD@{1} (badcafe). You can do this by running:

$ git reset badcafe

Hope this helps!

cheers,

Tim

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2014

Great advice. I just wanted to emphasize that any COMMITTED work has not been lost. If you had anything uncommitted (unlikely, since you said you were working on a merge), then it will have to be recreated. In the future, a "mixed" reset is safer, because it will reset your branch to the selected commit, but it will make no changes to your working copy.

Like Mehmet Şirin Yilmaz likes this
TimP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2014

Excellent point @Seth. There is some [dark magic|http://www.reddit.com/r/git/comments/2byaww/ok_i_really_screwed_up_i_did_a_git_rm_f_on_an/] you can use if the work was added to the index but not committed too, although it's not quite as straight forward as a reset.

lmiguelmh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 25, 2014

Thanks a lot for your answers... and I am sorry to say that none of my changes were committed and neither added to GIT... So I think I will have to try to recover the files from disk (if they were not rewritten) and surely I will have a long long night... Again, thanks a lot.

christiaan.net
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 29, 2015

I love u! I thought I lost 2 days of work....

byiddish
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 17, 2017

Thank you so much!!!

You saved me 2 weeks of work!

ahmarcusjo@gmail.com
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 25, 2017

I owe you for this..Big time!

Davor Poznič
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 22, 2018

Thank you. You just saved me from a lot of troubles. I owe you a beer. 

eyesofjeremy November 28, 2018

Thank you so much — this just helped me out too!

serhii_k
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 12, 2020

Thank you so much!

0 votes
jauseg
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 13, 2019

wow! it is not only helped me to restore my changes but make me better understand how the git works. thanks!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events