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

Re: Disappearing change on pull rebase

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 11, 2011, 16:31 UTC
Message-ID
<7vzkg2r56y.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4EBCC71D.6000505@viscovery.net>
Johannes Sixt <j.sixt@viscovery.net> writes:
Show 17 quoted lines
> Am 11/10/2011 14:35, schrieb Pitucha, Stanislaw Izaak:
>> As mentioned in the original mail - the merge commit did have changes.
>> Here's the log of reproducing it. The line containing "2" in changelog
>> is gone from master after pull --rebase.
>> ...
>> disappearing_commit$ git merge --no-ff --no-commit some-branch
>> Automatic merge went well; stopped before committing as requested
>> disappearing_commit$ echo 2 >> changelog 
>> disappearing_commit$ git add changelog
>> disappearing_commit$ git commit
>> [master e41e4c9] Merge branch 'some-branch'
>
> This is by design. Rebase does not rebase merge commits because it is
> assumed that merge commits only do what their name implies - to merge
> branches of a forked history. As such, they do not introduce their own
> changes. Follow this rule, i.e., make your change in a separate non-merge
> commit, and you are fine.

While that may be technically correct, I wonder if we can be a bit more helpful to the users in such a case (upfront I admit that I have a strong suspicion that this is a hard problem in general). One typical use of "rebase" is to linearize a history that has unfortunate merges that did not have to be there, so refusing "git rebase A..B" when there is a merge in "git rev-list --merges A..B" is not a solution. But would it help if we warned about the merges when we find that there is something _interesting_ going on in them, e.g. an evil merge that adds material that did not exist in any of the parents [*1*]? The warning message may diagnose "you asked me to linearize the history by picking commits on the non-merge segments and replaying them, but there may be changes made in this merge commit, and it does this interesting thing: $(git show -c $that_merge_commit)" and may further suggest "if you do not want to linearize but just transplant the history, perhaps you want to run the command with the '-m' option?".

[Footnote]

*1* This is a hard problem and not just the matter of looking at "show -c" output. A "-s ours" merge would appear empty in "show -c" but it _is_ an interesting event that makes the result of linearizing non-merge segments vastly different from the original. Also material that did not exist in any of the parents is not necessarily evil (e.g. the side branch may have added one parameter to a function and updated its call sites, while our branch may have added a different parameter to the same function. The update to the call sites in the merge result should pass two more parameters from the common ancestor, and different from either of the parents).

Previous: Philippe Vaucher
Message 8 of 8 in “Disappearing change on pull rebase”
  1. Pitucha, Stanislaw IzaakNov 10, 2011
  2. Kirill LikhodedovNov 10, 2011
  3. Pitucha, Stanislaw IzaakNov 10, 2011
  4. Johannes SixtNov 11, 2011
  5. Philippe VaucherNov 11, 2011
  6. Johannes SixtNov 11, 2011
  7. Philippe VaucherNov 11, 2011
  8. Junio C HamanoNov 11, 2011

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.