问题描述
在Git中,我知道分支是指向提交的指针.
In Git, I understand that a branch is a pointer to a commit.
如何将特定分支指向特定提交?假设我想将master
指向1258f0d0aae...
,该怎么做?
How do I make a specific branch point to a specific commit? Say I want to make master
point at 1258f0d0aae...
, how do I do that?
推荐答案
您可以这样将master
指向1258f0d0aae
:
git checkout master
git reset --hard 1258f0d0aae
但是您在执行此操作时必须小心.它很可能会重写该分支的历史记录.如果您已经发布了该出版物,而其他人正在该分支上工作,那将会造成问题.
But you have to be careful about doing this. It may well rewrite the history of that branch. That would create problems if you have published it and other people are working on the branch.
此外,git reset --hard
命令将丢弃所有未提交的更改(即,仅在您的工作树或索引中的那些更改).
Also, the git reset --hard
command will throw away any uncommitted changes (i.e. those just in your working tree or the index).
您还可以通过以下方式强制更新分支:
You can also force an update to a branch with:
git branch -f master 1258f0d0aae
...但是如果您当时在master
上,git不会让您这样做.
... but git won't let you do that if you're on master
at the time.
这篇关于如何在特定提交上创建分支点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!