0

In my feature branch, I rebased off main in CLion which resulted in a couple of file conflicts and after solving them, I do:

git log
# commit <commitID-3>
# commit <commitID-2>
# commit <commitID-1>

git status 
# Your branch is up to date with 'origin/featureBranch'

# rebase off main in CLion 
# resolve conflicts

git status
# On branch <featureBranch>
# Your branch and 'origin/<featureBranch>' have diverged,
# and have 14 and 7 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
  • Does the following line imply the difference between local & remote branches?

Your branch and 'origin/' have diverged,

  • How does the local branch have 7 extra commits? It's not including the ones I rebased, yes? How can I view the difference if even?

and have 14 and 7 different commits each, respectively.

  • Where's the commit that involved fixing a conflict?

  • Is the solution to force push?

xyf
  • 664
  • 1
  • 6
  • 16
  • 1
    I'm not sure there's enough here to know what happened. Divergence is more than a difference between local and remote. You can certainly force push, but that effectively replaces the remote branch, so any other developers would be detached. They'd need to delete their local and check out the new remote. – isherwood Dec 08 '22 at 21:30

1 Answers1

1

This is a usual thing that happens when you rebase a branch.

git rebase takes all the commits from your local branch that don't exist on the other branch (main) and sets them aside. It then takes and updates the local branch with all the new commits from the other branch. After that is complete it then applies your other commits one and at a time. If there is a conflict in applying the commit, it asks you to resolve it and commit.

The reapplying of the commit results in a new commit SHA (and if there are conflicts in the rebase a different set of changes).

Git uses the commit SHA's to identify changes. So when you are comparing your local branch to the remote branch, git sees 7 SHA's that are on origin/<featureBranch> that aren't on your local. As well as 14 SHA's that you have on your local branch but are not present on origin.

The seven commits on the remote are the ones that git reapplied using rebase along with your changes for the resolving the conflict. You resolved the conflicts be actually changing what is in the commit (this is a feature of rebase). If you had wanted a single commit showing the conflict resolution, then you would have wanted to have done git merge.

You can resolve this via a force push. However, this may not be the right solution depending on if other people are developing on the remote branch as well. Since git rebase is a rewriting of history. It might not be a good idea depending on what the commits that are on the remote that you are overwriting are. (you can git checkout origin/<featurebranch> followed by git log to see if the commits are pretty much the same)

Schleis
  • 41,516
  • 7
  • 68
  • 87