开发者

git checkout from remote

I have been reading other questions on stack overflow but nothing simply explains what I need. I am pushing to a remote repo with one other collabora开发者_开发问答tor. I want to check out a past commit from a few weeks ago. How do I do this?


git checkout -b <branch_name> <sha1>

(this will create a new branch and checkout at that particular commit that you want)

If you just want to reset current branch to it:

git reset --hard <sha1>

Update on sha1:

What I meant by Sha1 is this long hash that is associated with each commit and identifies it. You can easily find it by doing a git log

Sample git log output:

commit 10a45e0f0680b8fd493ed0264fe24be2648af1b3
Author: manojlds <manojlds@gmail.com>
Date:   Thu Oct 13 19:04:23 2011 -0600

    some other commit

10a45e0f0680b8fd493ed0264fe24be2648af1b3 is the sha1 hash.


 git log # to check what SHA1 you need
 git checkout -b tmp SHA1 # to checkout the right SHA1 and create a tmp branch

If you checkout directly a SHA1, you would end up with a DETACHED HEAD, with the risk of making some unreferenced commits.
See for instance "git: how to retrieve all files as of a certain date".

Note that you have various syntax to checkout by date:

<refname>@{<date>}, e.g. master@{yesterday}, HEAD@{5 minutes ago}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜