是否有可能在未检查出的情况下快进另一个分支? [英] Is it possible to fast forward another branch without checking it out?
问题描述
在git中,我有一个分支 A
。我创建了另一个分支 B
,我创建了一些提交。然后,我想快速转发分支 A
到分支 B
。
In git, I have a branch A
. I create another branch B
where I create few commits. Then I want to fast forward branch A
to branch B
.
我知道我可以签出 A
并快速转发到 B
的最新提交。这个操作需要对工作副本进行两次修改:第一次返回到 A
,然后将工作副本恢复到 B
。如果 B
上的新提交包含很多更改,则操作可能会很慢。
I know that I can checkout A
and do fast forward to the latest commit of B
. This operation requires two modifications of working copy: the first to return to A
and then revert working copy to B
. If new commits on B
contain a lot of changes, the operation could be quite slow.
是否可以在不更改工作副本的情况下快速转发另一个分支? (换句话说,只需移动 A
的指针)
Is it possible to do fast forward another branch without changing the working copy? (in other words, to move just the pointer of A
)
推荐答案
Git提供了更新参考为此目的的命令
Git provides the update-ref command for this purpose
git update-ref A B
注意:该命令是较低级别的Git命令之一,并且不提供任何防范措施以避免让自己陷入困境。如果B不是A的快进,它仍然会更新A,可能会使提交无法访问并受到垃圾回收。
Note: This command is one of the lower-level Git commands and does not provide any safeguards for you to keep from screwing yourself up. If B is not a fast-forward of A it will still update A, potentially making commits unreachable and subject to garbage collection.
这篇关于是否有可能在未检查出的情况下快进另一个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!