Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git reset --hard not working as expected

Tags:

git

git-reset

I am trying to inspect the history of a repository. I stopped at a point where I want to return the repository back to a specific commit. I searched and I did

git reset --hard 12345

I got the message that HEAD is now at 12345. I opened the folder to see the file I wanted to see but it didn't change!

I wanted to go back to 2009 when that file first created. However the file was in the new version (after editing it in 2010).

I checked the working directory but nothing there. I also ran

git clean -f -d

but nothing changed.

I don't know what should I do now. I want to go back in time to see how files were look like, but I want to go back to the whole repository.

like image 612
Arwa Avatar asked Jan 30 '15 21:01

Arwa


1 Answers

To be fair, I do not understand what happened to your repo after you did

git reset --hard 12345

What should be stressed is that you should usually avoid "git reset --hard" command. The risk is to lose any uncommitted change that you had and also end up with dangling commits. You would really use that command if you want to throw away all the commits that have been made after commit 12345. I invite you to read this thread about git reset --hard

In your case, I would actually have created a temporary branch "temp_branch" that would point towards the commit 12345. The command would be

git checkout -b temp_branch 12345

This will switch the repo to new branch "temp_branch", whose HEAD will be 12345. The creation of a new branch is not compulsory but I find it convenient if I need to make a change from that commit.

like image 140
iclman Avatar answered Sep 28 '22 17:09

iclman