Git rebase 无参数版本与有参数版本

Git rebase no argument version vs one argument version

我阅读了很多有关 SO 和 Git 文档的内容,并注意到一些我不完全理解的内容:

假设我有以下状态和配置 post-fetch,git 拉取的第 2 阶段,并且在 origin/master 上发生了强制更新:

$ git log -2 --oneline
a589c89 foo2
e0e5946 foo

$ git log -2 --oneline origin/master
e0e5946 foo

$ git config branch.master.remote
origin

$ git config branch.master.rebase
true

$ git config branch.master.merge
refs/heads/master

文档说 (https://www.kernel.org/pub/software/scm/git/docs/git-rebase.html)

If <branch> is specified, git rebase will perform an automatic git
checkout <branch> before doing anything else. Otherwise it remains on
the current branch.

If <upstream> is not specified, the upstream configured in
branch.<name>.remote and branch.<name>.merge options will be used

当我指定 git rebase 的单参数版本时,会发生这种情况:

$ git rebase origin/master
Pruned remote csv test branches
Successfully rebased and updated refs/heads/master.

$ git log -2 --oneline
a589c89 foo2
e0e5946 foo

太棒了,foo2 仍然存在于我的本地分支机构中。现在这样做,这应该是同一件事(隐含地),因为根据文档,branch.master.remote 和 branch.master.merge 解析为 origin/master,如上所示,除非我解释错了:

$ git rebase
Pruned remote csv test branches
Successfully rebased and updated refs/heads/master.

$ git log -2 --oneline
e0e5946 foo

除非 foo2 丢失,我们必须 git reset --hard HEAD@{2} 才能恢复。真的没想到那个。知道为什么我在这里有不同的行为吗?我将如何防止 foo2 在 过程中丢失而不 将 branch.master.rebase 切换为 false?我打算拉动做一个变基。

差异取决于您的特定 Git 版本。

目前(Git 版本 2.something 以上,我不确定是什么东西),最大的区别是三参数版本 禁用 --fork-point 默认情况下,而双参数版本 默认启用 它。

git pull 引入组合中会使事情变得更加棘手,因为 git pull--fork-point 的起源,而 Git 的旧版本与新版本的行为有很大不同.特别是,在 --fork-point 是它自己的单独选项之前, git pull 进行了分叉点样式的变基。我怀疑这在您的特定 Git 版本中是一个问题,因为这样您就不会看到 git rebase origin/mastergit rebase 的区别(branch.master.* 配置提供 <upstream>).至少,我认为你不会。

(为了完整起见,您可能想要显示 git config --get-all remote.origin.fetch 的输出,尽管我希望它是 +refs/heads/*:refs/remotes/origin/* 的标准单行。)

进一步阅读--fork-pointthe git rebase documentation and the git merge-base documentation section on --fork-point