使用git branch -f或git update-ref来快速提供现有分支会更好吗? [英] Is it better to use git branch -f or git update-ref to fast-forware existing branch?

查看:136
本文介绍了使用git branch -f或git update-ref来快速提供现有分支会更好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到我可以使用 git update-ref 来快进我不在的现有分支。然后我发现类似的东西可以通过 git branch -f 来完成。我知道 git update-ref 更加灵活(它可以移动任何ref),但它可能是危险的。那么使用 git branch -f 会更好吗?这两个命令在这些特定场景中是否有区别? (除此之外,我可以指定自定义ref日志消息。)

解决方案

使用 git branch -f ,它会拒绝更新分支,如果它是(如果它是当前分支)

refrel =nofollow noreferrer> git update-ref 没有这个限制。






Qqwy 增加了另一个区别在评论 a>:


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.)

解决方案

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 has not that limitation.


Qqwy adds another difference in the comments:

  • 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.

这篇关于使用git branch -f或git update-ref来快速提供现有分支会更好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆