简体   繁体   中英

Git branch diverged after rebase with no changes

When I call git rebase --interactive HEAD~2 , I get a list of 22 commits instead of the expected 2.

Also, when I save and close without changing anything, I still get the message "Your branch and 'origin/x' have diverged, and have 22 and 23 different commits each, respectively.

Why does it show 22 commits instead of 2 and why does it diverge without me changing anything?

Edit: As requested, more details:

Commit Log

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.
[...]

Commits shown by $ 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)
# [...]

Now I don't do anything, just close vim via :wq and I get the following message:

$ 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: OK I get it now, you pointed me in the right direction with the merge commits, after reading Rebasing a Git merge commit I now understand that rebase drops merge commits, so my "no changes" is actually a change after all (dropping the single merge commit).

You need to make sure using git log is there's only 2 commit, or also another 'dummy commit' from your previous merge action.

git rebase -i HEAD~N is only get your last N commit.

if you want to undo diverge or any event, you can do this :

  1. git reflog find your hash last commit before rebase happen.
  2. git checkout <commit-hash> to check or, git reset --hard <commit-hash> to reset HEAD ref to selected commit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM