Git rebase没有参数版本与一个参数版本

时间:2016-06-14 09:16:29

标签: git rebase pull

我在SO和Git文档上阅读了很多东西,并且在弄乱之后注意到了一些我不完全理解的东西:

让我说我有以下状态和配置后取,git pull的第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,如上所示,除非我解释错误:< / p>

$ 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的过程中丢失?我打算让拉力去做一次改变。

1 个答案:

答案 0 :(得分:1)

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

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

在混合中引入git pull会让事情变得更加棘手,因为git pull--fork-point的起源地,而旧版本的Git的行为与新版本相比更加不同。特别是,在--fork-point是其自己的单独选项之前, git pull执行了fork-point样式的rebasing。我怀疑这是你的特定Git版本中的一个问题,因为你不会看到与git rebase origin/master vs git rebasebranch.master.*配置提供<upstream>)的区别。至少,我认为你不会。

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

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