为什么git重设--硬导致派生分支在重设基础时也重设?

为什么git重设--硬导致派生分支在重设基础时也重设?,git,Git,有时我想把我最近在一个分支上的工作分成一个新的分支 # Create a new branch tracking the old branch git branch -t new-branch # Reset the old branch to a prior commit git reset --hard HEAD~3 git checkout new-branch 我希望git-rebase现在什么都不做,因为文档中说: All changes made by commits in t

有时我想把我最近在一个分支上的工作分成一个新的分支

# Create a new branch tracking the old branch
git branch -t new-branch

# Reset the old branch to a prior commit
git reset --hard HEAD~3

git checkout new-branch
我希望
git-rebase
现在什么都不做,因为文档中说:

All changes made by commits in the current branch but that are not in <upstream>
are saved to a temporary area. This is the same set of commits that would be shown
by git log <upstream>..HEAD; or by git log 'fork_point'..HEAD, if --fork-point is
active (see the description on --fork-point below)....
提交在当前分支中所做但不在当前分支中的所有更改
保存到临时区域。这是将显示的同一组提交
通过git log..头;或者通过git日志“fork_point”…HEAD,如果--fork point是
活动(请参见下面关于--fork point的描述)。。。。
因此,
新分支
重置为
旧分支
,并应用任何保存的更改。这些保存的更改不应该包括指向的提交
新分支
,而这些提交不再可以从
旧分支
访问吗


相反,
新分支
被重置为
旧分支
,提交消失。

仔细阅读文档,我发现:

   If <upstream> is not specified, the upstream configured in branch.<name>.remote
   and branch.<name>.merge options will be used (see git-config(1) for details) and
   the --fork-point option is assumed.
merge base
很复杂,但在本例中,它检查reflog并实现以前存在于我们分支的分支中的“新”提交,并返回与
new branch
相同的提交,也就是
HEAD
,因此
git log fork\u point..HEAD
不返回任何内容。然后,重基不会最终保存和应用新提交


等价地(但您必须记住这一点),您可以在以后重定基址时使用
--无分叉点
,或者明确说明要重定基址的本地分支,即使它已经设置为上游分支。这基本上是卑鄙的自动
——fork point
代码的一个非常糟糕的结果,在我看来,这是一个很酷的(或“kewl”?)想法,但后来证明它比它的价值更麻烦。:-)(此外,我还编辑了原始问题的accepted/community wiki答案以添加警告。)
git merge-base --fork-point <upstream> <branch>