开发者

How to get back to a specific time of version of a file in Git?

I have made several commit开发者_运维问答s to a file. How could a get back to a specific version of time of that file?

Thanks.


Use git log to see the commits you made and choose the one you want to get back. Note its SHA1 hash.

Then use git checkout to get to that version of the file:

git checkout f93b3e path/to/file

In fact, any tree-ish will work here. For instance, if you wanted the file as it was last month you could do:

git checkout master@{1 month ago} path/to/file


If you want a visual tool use gitk from the branch in question.

As you select various commits you can inspect content to find the right one.

You can right click on the commit to check out the whole commit out as a 'detached head', that is, it will be detached from the branch's tip.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜