git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Rebase Question

From
Jeff King <peff@peff.net>
Date
May 12, 2021, 00:44 UTC
Message-ID
<YJsk49WBd27NrCAA@coredump.intra.peff.net>
In-Reply-To
<CAGyf7-GEA0mtxUxqEjYsfqM4Te-5JO5_nW0S6Vitdmywz1J7mg@mail.gmail.com>
On Tue, May 11, 2021 at 05:29:03PM -0700, Bryan Turner wrote:
Show 21 quoted lines
> On Tue, May 11, 2021 at 5:07 PM Andrew Ottaviano <andrew_o1995@live.com> wrote:
> >
> > Hello all!
> >
> > I’ve used git for a few years now and I
> > think it is an amazing tool! Thank you for your hard work in
> > developing/maintaining it! I really appreciate it!
> >
> > I have a question. Let’s say that my
> > colleague and I branch off of master and are working. Let’s say I’m 5 commits
> > ahead of master and my colleague merges in ahead of me. The logical thing in my
> > mind is to rebase off of master. The difficulty with this is that if I have
> > merge conflicts that show up on my first commit, I have to resolve that stupid
> > thing for every subsequent commit. I could squash, but then I loose branch
> > history, so I don’t really want to do that. I could rebase in interactive mode,
> > but if I recall, I still need to resolve all the conflicts on every commit
> > before it squashes.
> 
> Have you investigated git rerere[1] at all? Documentation indicates it
> works for rebase as well as merge, so it might be possible to train
> that to resolve the conflicts.

I don't think rerere helps here. In a rebase like this, the problem is that it _isn't_ the same conflict.

Imagine a case like this:

-- >8 -- git init repo cd repo

# both branches start with just the line "base" echo base >file git add file git commit -m base

# one side adds a new line git checkout -b newline echo another >>file git commit -am 'add a line'

# and the other modifies the first line git checkout -b other HEAD^ echo one >file git commit -am one echo two >file git commit -am two

# and now we rebase on top of the newline branch git rebase newline -- >8 --

Applying the first commit gets this conflict (in diff3 form)
  <<<<<<< ours
  base
  another
  ||||||| base
  base
  =======
  one
  >>>>>>> theirs
After we fix that up to "one\nanother", the second conflict is:
  <<<<<<< ours
  one
  another
  ||||||| base
  one
  =======
  two
  >>>>>>> theirs

Likewise, even if you had done the original merge between branch tips, you'd have seen yet another conflict:

  <<<<<<< ours
  two
  ||||||| base
  base
  =======
  base
  another
  >>>>>>> theirs

The actual lines changed are the same, but as the nearby context is continually shifting, we don't consider these to be the "same" conflict.

-Peff
Previous: Bryan TurnerNext: Junio C Hamano
Message 4 of 6 in “Rebase Question”
  1. Andrew OttavianoMay 12, 2021
  2. Jacob KellerMay 12, 2021
  3. Bryan TurnerMay 12, 2021
  4. Jeff KingMay 12, 2021
  5. Junio C HamanoMay 12, 2021
  6. Felipe ContrerasMay 12, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.