【发布时间】:2014-04-01 15:49:06
【问题描述】:
我正在尝试在 master 之上重新建立一个分支,我之前已经做过一千次了。但是今天,它不起作用:
> git status
On branch mystuff
Your branch and 'master' have diverged,
and have 6 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean
> git rebase
First, rewinding head to replay your work on top of it...
> git status
On branch mystuff
Your branch is up-to-date with 'master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
[a directory from the project]
nothing added to commit but untracked files present (use "git add" to track)
>
一切都开始正常,但随后 Git 完成了 rebase,但没有将我的任何提交放在那里;我的分支 mystuff 最终与 master 提交相同的提交。
显而易见的结论是我的提交已经在某个地方的 master 中。但他们不是,我发誓。我已经回顾了历史。提交 在其他几个功能分支上,但它们不在任何地方的 master 历史记录中。 (而且我可以通过文件的状态来判断他们不在 master 中,当我有 master 签出时。)
那么,如果提交不在我的上游历史记录中,为什么 git rebase 会拒绝将我的提交放在最上面?
奇怪的是,如果我一个接一个地挑选提交到 master 上,那是可行的。然后我可以将 mystuff 分支移动到最后,然后将 master 恢复到原来的位置。 (但为什么我需要那样做呢?)
编辑:
git rebase 上的文档是这样说的:
如果提供了
--onto选项,当前分支将重置为<upstream>或<newbase>。这与git reset --hard <upstream>(或<newbase>)具有完全相同的效果。ORIG_HEAD设置为在重置之前指向分支的尖端。然后将之前保存到临时区域的提交按顺序一一重新应用到当前分支。请注意,
HEAD中引入与HEAD..<upstream>中的提交相同的文本更改的任何提交都将被忽略(即,将跳过已在上游接受的具有不同提交消息或时间戳的补丁)。
这与我看到的行为一致如果提交实际上存在于上游......但他们没有。正如 cmets 中所述,git rebase master 可以正常工作并应用所有提交。但是没有master 的git rebase 不会,即使master 被设置为上游分支。
我的分支配置:
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "mystuff"]
remote = .
merge = refs/heads/master
【问题讨论】:
-
git rebase返回后的git status是什么? -
当您执行
git rebase master或git rebase master <branch>时会发生什么? -
是否可以共享整个目录?如果你那确定你做的很好,它可能有助于找到一个错误或任何东西。
-
@Irineau,请参阅编辑。未跟踪的目录是因为未重新设置的提交之一是更改 .gitignore 以忽略该目录。
-
@Cupcake,好问题。
git rebase和git rebase --onto master都像上面一样失败......但是git rebase master有效!但为什么?如果 master 是上游,那么git rebase应该在没有分支参数的情况下工作,不是吗?
标签: git git-rebase