1

I'm trying a git rebase to squash some commits down. However each time I have to manually resolve conflicts on what seems like every step. Basically every single commit I made shows as a conflict and I have to resolve it.

Is it possible to use rebase when I have made some branches while working on a project? These are just local branches that haven't been pushed to origin yet.

dcsan
  • 11,333
  • 15
  • 77
  • 118
  • 2
    Perhaps the issue is your understanding of how rebase works. During a rebase, your branch is first unwound back to the last common commit with the parent branch. Then, the latest commits from that parent are played on your branch, and finally all your commits/work are _reapplied_ to that branch. As each of your commits are reapplied, there can be conflicts, this is normal. – Tim Biegeleisen Jun 08 '20 at 09:02
  • Show us an example of the CLI git commands you run when you rebase the feature of a topic branch on the main branch (e.g. master). – tonix Jun 08 '20 at 09:03
  • It gives merge conflicts when changes in your branch can't be safely reapplied to the target commit. – choroba Jun 08 '20 at 09:14
  • If you had a branch `A -> B` and you create a new branch from it, then you'd have `A -> B -> C -> D -> E` *however*, the main branch could also move forward to and have `A -> B -> X -> Y -> Z`. If you rebase your commits on that main branch and the first (`C`) conflicts you'd have to resolve that. This creates a *new commit*, let's call it `C'`. Any of the later commits (`D` and `E`) that modify the same thing as the first one will now be inapplicable as you now have different code there, thus each will conflict. You're better off rewriting history first, then rebasing to another branch. – VLAZ Jun 08 '20 at 11:22
  • can you explain a bit more @VLAZ? maybe make an answer? – dcsan Jun 08 '20 at 13:35
  • I was giving generic information on rebasing. In order to give you a proper answer we need a bit more information on what you're trying to do in order to find how to improve it. – VLAZ Jun 08 '20 at 13:47

1 Answers1

0

This is a common misunderstanding of rebase vs merge. You get conflicts when git cannot resolve changes (textual or otherwise) automatically, ie. changes were done at the same place. The choice is not between rebasing or merging, but integration frequency.

Joel Lim
  • 46
  • 1
  • 3