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

On merging strategies, fast forward and index merge

From
MWMark Wooding <mdw@distorted.org.uk>
Date
Mar 18, 2006, 10:17 UTC
Message-ID
<slrne1nnhm.fr9.mdw@metalzone.distorted.org.uk>

I recently read Junio's description of how to dig oneself out of a hole using `git merge -s ours' (I'm learning to use the space...), and I've realised there's a problem here.

The `ours' merge strategy is meant to create a merge commit whose tree is in every way identical to that of the starting commit. But `git merge' won't always do this, because it doesn't always invoke the strategy program.

Consider the command `git merge -s ours MESSAGE MASTER FAILED'.
  * If we've not actually messed with our MASTER since the FAILED branch
    departed, then MASTER is actually an ancestor of FAILED, and `git
    merge' will unhelpfully fast-forward us to the tip of the FAILED
    branch.  Instead of leaving the merge result like MASTER, it's made
    it entirely the wrong thing!
  * If both MASTER and FAILED have made changes, but to different files,
    then `git merge' will try an index-level merge, find that it
    succeeds, and leave us with a mixture of MASTER and FAILED files.
    Which is (in this case) entirely what we didn't want.

Additionally, it occurs to me that the fast-forwarding behaviour isn't always what I want anyway. Consider a merge of a topic branch:

  `git merge MESSAGE MASTER TOPIC'

If I allow fast-forward, I lose information about where the topic started and ended. This is a shame, particularly if I find other places I want to apply those changes (either as a string of similar commits, or squidged into a single one) onto other branches.

Because code speaks louder, I'll follow-up this article with a suggested patch.

-- [mdw]
Next: Mark Wooding
Message 1 of 4 in “On merging strategies, fast forward and index merge”
  1. Mark WoodingMar 18, 2006
  2. git-merge: New options `--no-fast-forward' and `--direct'.Mark Wooding, Mar 18, 2006
  3. Junio C HamanoMar 18, 2006
  4. Junio C HamanoMar 18, 2006

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.