重新设置基准后,Git分支出现了分歧

时间:2020-10-01 09:59:34

标签: git rebase

当我致电git rebase --interactive HEAD~2时,我得到了22次提交的列表,而不是预期的2次。

此外,当我保存并关闭而不进行任何更改时,仍然收到消息“您的分支和'origin / x'已经分开,分别具有22和23个不同的提交。

为什么它显示22次提交而不是2次提交,为什么在我不做任何更改的情况下它就会发散?

编辑:根据要求提供更多详细信息:

提交日志

commit 9e50b1e5e32825c7829dd8ac2dd68ff00035bb91 (HEAD -> feature-m, origin/feature-m)
Author: A
Date:   Wed Sep 30 16:49:08 2020 +0200

    Fix fetch path.

commit 969125bdfc34a1814962f243bc35d7e1b8909691
Merge: d6acd57 5f4788a
Author: B
Date:   Wed Sep 30 16:43:42 2020 +0200

    Merge branch 'feature-m' of github.com:x/y into feature-m

commit 5f4788acc15387852a6d5a38887ea6094b808426
Author: B
Date:   Wed Sep 30 16:33:43 2020 +0200

    Include state when saving and loading session. Resolve #305.

commit 7395f43849c6c39b424a4f783472b873ca16eb10
Author: B
Date:   Wed Sep 30 16:27:02 2020 +0200

    Fix context menu bug. Resolve #316.

commit 07d184f0c6f1de32ddf3b9c314d9e21bc073122f
Author: B
Date:   Wed Sep 30 15:49:18 2020 +0200

    Fix daymode tab bug, resolves #314.
[...]

$ git rebase --interactive HEAD~2显示的提交

pick e1e1025 Change this.graph entries in menu and main.
pick 234ea9a Add Cypress.io for e2e tests and first ui tests. See #298.
pick 362a4e9 repair tests and add a new one.
pick 042b344 Continue e2e-tests.See #298.
pick 6ca634e Resolve #301: disable copy and paste when not fired from body directly.
pick 2279dbc Resolve #302: Adapt filters to multiview.
pick 355721a Resolve #303: correct view layout to apply the header functions in the proper view.
pick eb89de8 Fix #304: Paste edges along with nodes.
pick 7b17df3 Apply combine matches to all tabs. Part of #288.
pick d080a94 Apply instances loaded to all tabs. Still suffers from a bug that also occurs on the master branch, see #306. Part of #288.
pick 9f9e808 Add config to the session file on save. Part of #305.
pick 559b0e2 Add confirm dialog on load session. See #299.
pick 7389b58 add state object, part of #305.
pick dcc047a save version into session file and warn about old files, resolves #309.
pick 8c74326 save and load filters, structure state.js, part of #305.
pick b882fba Change the menu to a singleton. Resolve #315.
pick fc44dc4 Change the menu to a singleton. Resolve #315.
pick 03a3527 Apply grid using a css class on body. Resolve #316.
pick 07d184f Fix daymode tab bug, resolves #314.                                                                                                              
pick 7395f43 Fix context menu bug. Resolve #316.
pick 5f4788a Include state when saving and loading session. Resolve #305.
pick 9e50b1e Fix fetch path.

# Rebase d6acd57..9e50b1e onto 7395f43 (22 commands)
# [...]

现在我什么也没做,只需通过vim关闭:wq,我会收到以下消息:

$ git rebase --interactive HEAD~2   
Successfully rebased and updated refs/heads/feature-multiview.
gitprob$ git st
On branch feature-multiview
Your branch and 'origin/feature-multiview' have diverged,
and have 22 and 23 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean

PS:好的,我现在明白了,您在读了Rebasing a Git merge commit之后就用合并提交向我指出了正确的方向,现在我了解到rebase会丢弃合并提交,因此我的“无更改”实际上是在更改之后全部(删除单个合并提交)。

1 个答案:

答案 0 :(得分:1)

您需要确保使用git log仅存在2次提交,或者您先前的合并操作中还有另一次“虚拟提交”。

git rebase -i HEAD~N仅得到您的最后N次提交。

如果要撤消分歧或任何事件,可以执行以下操作:

  1. git reflog在变基发生之前找到您的哈希上一次提交。
  2. git checkout <commit-hash>检查或git reset --hard <commit-hash>重置HEAD ref为选定的提交。
相关问题