0

In my local branch, I ran the following to get the latest commits from main and rebase on top

$ git pull --rebase origin main

but ended up seeing a few conflicts. Seemingly resolved them but git status shows my branch has diverged.

$ git status
Your branch and 'origin/branch' have diverged,
and have 8 and 5 different commits each, respectively.
  • My remote is all fine and contains the latest local changes before I rebased locally, and it contains 5 commits. Where am I getting the extra 3 commits from? The commits that my local branch rebased on top of?

  • I see one of the files that I added (which was deleted in one of the commits from main) is no longer locally there. Why that may be?

So conflicts are resolved, but how do I get my branch up and running from the mess it's in?

is force push the way? Are there consequences?

xyf
  • 664
  • 1
  • 6
  • 16
  • You rewrote the history of your branch when you did rebase pull. You may have to force push. – Tim Biegeleisen Jan 16 '23 at 23:10
  • How do I get the "deleted" file back though which is in remote but gone locally after rebase? I am afraid force push would guarantee not accessing the lost file at all – xyf Jan 16 '23 at 23:11
  • Should that file really still be there? – Tim Biegeleisen Jan 16 '23 at 23:14
  • Why not? It's the file that I created locally (pushed to remote) but one of the commits deleted the same file. So why local changes didn't take precedence? – xyf Jan 16 '23 at 23:16
  • 1
    Because during the rebase, the remote branch version was being treated as the "local" one or source of truth. – Tim Biegeleisen Jan 16 '23 at 23:24
  • "Diverged" means: "different commits locally vs remote". You rebased. Rebasing means: you no longer have the original commits, but replaced them with new and distinct commits → diverged, because different commits locally vs remote. As for the deleted file: we'd have to see the actual commits (with name-status) to be able to answer that. – knittl Jan 16 '23 at 23:40
  • "is force push the way ?" : check that your code makes sense (review it, test it, run it ...), once you have validated that, yes, force push is the way – LeGEC Jan 17 '23 at 04:57

0 Answers0