最好使用git branch -f或git update-ref来快速转发现有分支? [英] Is it better to use git branch -f or git update-ref to fast-forward existing branch?

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

问题描述

我意识到我可以使用 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 <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.

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

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