【问题标题】:Is it better to use git branch -f or git update-ref to fast-forward existing branch?使用 git branch -f 或 git update-ref 快进现有分支更好吗?
【发布时间】:2014-11-05 08:25:38
【问题描述】:

我意识到我可以使用git update-ref to fast-forward existing branch that I am not on。然后我发现git branch -f可以做类似的事情。我知道git update-ref 更加灵活(它可以移动任何参考)however it could be dangerous。那么使用git branch -f会更好吗?在这种特定情况下,这两个命令有什么不同吗? (除此之外,我可以指定自定义参考日志消息。)

【问题讨论】:

  • 仅供参考:即使使用update-ref 也没有丢失提交的真正危险,如您链接到的答案中所述。提交仍然存在,您仍然可以轻松恢复它们。

标签: git


【解决方案1】:

使用git branch -f,如果它是签出的分支,它将拒绝更新分支(所以如果它是“当前分支”)

git update-ref 没有这个限制。


Qqwy 又多了一个区别in the comments

  • git branch -f <branchname> [<start-point>] 将创建一个名为 <branchname> 的新分支,如果它不存在。
  • git update-ref <branchname> <newvalue> 在这种情况下不会做任何事情。

【讨论】:

  • 似乎update-ref 没有提供与branch -f 相同的自动完成功能。是否可以更改 git 的行为以为 update-ref 创建相同的体验?
  • @Zeeker 这将是一个很好的单独问题:我在这些命令的自动完成部分并没有看太多。
  • 我问过another question
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-14
  • 2018-06-25
  • 1970-01-01
相关资源
最近更新 更多