Git如何检出分支的提交 [英] Git how to checkout a commit of a branch
问题描述
如何在git
中检出分支的提交版本?
How can I check out a commit version of a branch in git
?
例如,我的分支Dev
具有提交ad4f43af43e
.我如何检查该提交?不只是单个文件,而是整个分支.
For example, my branch, Dev
, has a commit ad4f43af43e
. How can I check out that commit? Not just a single file, but a whole branch.
我在网上搜索后发现:git checkout <commit>
,但未指定分支名称
I searched online and found: git checkout <commit>
, but it didn't specify branch name
推荐答案
git checkout <hash> # non named commit
git checkout <branch_name> # named commit
以上两行将HEAD指针放在给定的提交上.您应该知道分支名称是一个提交,但是如果您在该分支上添加了新的提交,则分支名称可以演变.
The two lines above will place the HEAD pointer on the given commit. You should know that a branch name is a commit, except it can evolve if you a new commit is added when you're on that branch.
如果要将分支Dev
放置在提交ad4f43af43e
上,则可以这样做
If you want to place your branch Dev
on the commit ad4f43af43e
you can do this
git branch -f Dev ad4f43af43e
小心!这很危险,因为您可能会丢失提交
Be careful! This is dangerous because you may loose commits
这篇关于Git如何检出分支的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!