最好使用git branch -f或git update-ref来快速转发现有分支? [英] Is it better to use git branch -f or git update-ref to fast-forward existing branch?
问题描述
我意识到我可以使用 git update-ref
快速转发我不在的现有分支.然后,我发现git branch -f
可以完成类似的操作.我知道git update-ref
更加灵活(它可以移动任何引用),无论多么危险.那么使用git branch -f
更好吗?在这种特定情况下,这两个命令是否有任何区别? (除此之外,我可以指定自定义引用日志消息.)
I have realized that I can use git update-ref
to fast-forward existing branch that I am not on. Then I have found that similar thing can be done by git branch -f
. I understand that git update-ref
is much more flexible (it can move any ref), however it could be dangerous. So is it better to use git branch -f
? Are there any differences in these two commands in this particular scenarios? (Except of that I can specify custom ref log message.)
推荐答案
使用 git branch -f
,如果该分支是已检出的分支,则它将拒绝更新(因此,如果它是当前分支")
With git branch -f
, it would refuse to update the branch if it is the one checked out (so if it is the "current branch")
git update-ref
没有该限制.
git update-ref
has not that limitation.
Qqwy 添加了另一个区别
如果 这篇关于最好使用git branch -f或git update-ref来快速转发现有分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!git branch -f <branchname> [<start-point>]
不存在,它将创建一个名为<branchname>
的新分支. git update-ref <branchname> <newvalue>
将不执行任何操作.
git branch -f <branchname> [<start-point>]
will create a new branch called <branchname>
if it did not exist. git update-ref <branchname> <newvalue>
will do nothing in this case.