在重新定位后,什么可能导致“未来的提交数量”发生变化?

时间:2011-02-15 17:37:45

标签: git rebase git-rebase

在重新定位几个星期内我没有碰过的功能分支之前,它已经提前了25次提交。在变基之后,它现在是18次提交。在此过程中我必须解决几个冲突。可能正好是7。

什么可能导致这个数字变化?沿途被发现并变成NOOP的樱桃镐提交?上述冲突解决方案?

2 个答案:

答案 0 :(得分:4)

有一些可能的方法可能会发生 - 这不是一个详尽的清单,但应该让你知道这是如何产生的:

1。樱桃挑选的提交

首先,你提到了你的分支机构的提交被挑选到你正在重新定位的上游分支的可能性:为了确认这一点,git rebase将跳过任何这样的提交,这可能是差异的一部分。 VonCthis question的答案还有更多内容。

2。冲突解决了完全上游版本

我最初的怀疑是发生了什么事情,当你在变基础并看到冲突时,你总是通过选择上游版本而不是你的更改来解决它们。 (如果这不响铃,那么我的怀疑可能是完全错误的:))如果该提交没有引入其他非冲突的更改,那么你的冲突解决方案将做的是让树变得一样就像它试图从你的改变中应用补丁之前那样,所以没有什么可以提交的。

不幸的是,git在发生这种情况时提示你的提示可能相当令人困惑。这是你用git 1.7.1看到的一个例子。首先,提交一个与尚未从origin / master合并的更改发生冲突的更改:

$ git commit
[master 1efa20f] Add a change designed to conflict
 1 files changed, 1 insertions(+), 1 deletions(-)

...现在开始改变:

$ git rebase origin/master 
First, rewinding head to replay your work on top of it...
Applying: Add a change designed to conflict
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging src-plugins/3D_Viewer/ij3d/Image3DUniverse.java
CONFLICT (content): Merge conflict in src-plugins/3D_Viewer/ij3d/Image3DUniverse.java
Failed to merge in the changes.
Patch failed at 0001 Add a change designed to conflict

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".

看看冲突是什么:

$  git diff
diff --cc src-plugins/3D_Viewer/ij3d/Image3DUniverse.java
index 36ec046,f4841ec..0000000
--- a/src-plugins/3D_Viewer/ij3d/Image3DUniverse.java
+++ b/src-plugins/3D_Viewer/ij3d/Image3DUniverse.java
@@@ -264,7 -264,7 +264,11 @@@ public class Image3DUniverse extends De
        public void cleanup() {
                timeline.pause();
                removeAllContents();
++<<<<<<< HEAD
 +              contents.clear();
++=======
+               contents.clear(); // A change designed to conflict
++>>>>>>> Add a change designed to conflict
                universes.remove(this);
                adder.shutdownNow();
                executer.flush();

我已经决定喜欢上游的版本,所以编辑文件来解决这个问题:

$  vim src-plugins/3D_Viewer/ij3d/Image3DUniverse.java

解决冲突的解决方案:

$ git add src-plugins/3D_Viewer/ij3d/Image3DUniverse.java

现在尝试像往常一样继续使用rebase:

$ git rebase --continue
Applying: Add a change designed to conflict
No changes - did you forget to use 'git add'?

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".

我认为在更新版本的git中,它表明你可能刚刚解决了已经存在的提交,你应该考虑做git rebase --skip。然而,通常人们认为这是摆脱这种情况的唯一方法,所以:

$  git rebase --skip
HEAD is now at f3a2de3 3D Viewer: Avoid NPE when closing the viewer window.
Nothing to do.

该提交现在不会出现在git log

3。合并提交

你在下面的评论中提到你在之后检查两个分支时看到了几个合并提交 - 这也可能是缺少提交的原因,因为默认情况下git rebase会在准备其列表时忽略任何合并提交承诺重新申请上游。

答案 1 :(得分:1)

要稍微扩展Jefromi的评论,您可以将git log --pretty=oneline -n18 <branch>的输出与git log --pretty=oneline -n25 <branch>@{1}进行比较,看看哪些提交丢失了。正如他所提到的,如果你已经做了一些工作,你可能需要稍微使用git reflog,因为要确定哪个条目是你的rebase分支头。