hard not working as expected

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.


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.


If all you want to do is look at the content at commit, don't use reset. reset is for moving branches around and you can get yourself into trouble that way. Just check it out, git checkout 12345 . Then you can use checkout again to go back to where you were, git checkout master (or whatever branch).

As for your file not being changed, are you sure its different in that commit? Check with git diff 12345 branch_name -- filename .

链接地址: http://www.djcxy.com/p/37812.html

上一篇: 我想恢复到我的应用程序的备份副本

下一篇: 很难不按预期工作