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

"git merge" merges too much!

From
GWGreg A. Woods <woods@planix.com>
Date
Nov 29, 2009, 03:21 UTC
Message-ID
<m1NEaLp-000kn1C@most.weird.com>

I'm trying to learn to use Git to manage local changes. I'm very new to Git (hi all!), but not new at all to version tracking tools in general.

Hope I've found the right list on which to ask potentially naive questions! I've been doing _lots_ of reading about Git, but I can't seem to find anything about the problems I relate below.

One task I'm working on is to try to find the best way to merge changes made from one branch to another, eg. to propagate local fixes from one release to another.

However in at least one simple case "git merge" merges too much.

I have something like this started from a remote-cloned repository where BL1.2 is a branch from the remote master HEAD, which happens to correspond to a tag "TR1.2", the release-1.2 tag, and I've made three local commits to my local BL1.2 branch: A, B, and C:

                                         BL1.2 - A - B - C  <- BL1.2 HEAD
                                        /
master 1 - 2 - TR1.1 - 3 - 4 - 5 - TR1.2  <- master HEAD

(there are no "release" branches in this project, just tags on the master branch to represent release points -- is there any way to get "git log" to show which tags are associated with a given commit and/or branch? The real project is freedesktop.org's xinit repo, but the real tree is too messy to diagram here -- hopefully I've extracted the essence of the problem correctly)

I now want to create a branch "BL1.1" and merge commits A, B, and C to it in order to back-port my local fixes to the TR1.1 release. "TR1.1" is simply a tag on the origin/master trunk.

I do the following:
	git checkout -b BL1.1 TR1.1
	git merge BL1.2
However this seems to merge all of 3, 4, and 5, as well as A, B, and C.

I think I can (barely) understand why it's doing what it's doing, but that's not what I want it to do. However it looks like Git doesn't have the same idea of a branch "base" point as I think I do.

Running "git log TR1.2..BL1.2" does show me exactly the changes I wish to propagate, but "git merge TR1.2..BL1.2" says "not something we can merge". Sigh.

How can I get it to merge just the changes from the "base" of the BL1.2 branch to its head?

Is using either git-cherry-pick or "git log -p | git-am", the only way to do this? Which way best preserves Git's ability to realize if a change has already been included on the target branch, if any?

Is this the kind of "problem" that drove the creators of Stacked-Git to invent their tools?

Is there any way to get "git log --graph" (and/or gitk) to show me all the branch heads, not just the current/specified one?

-- 
						Greg A. Woods

+1 416 218-0098                VE3TCP          RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>      Secrets of the Weird <woods@weird.com>
Next: Jeff King
Message 1 of 33 in “"git merge" merges too much!”
  1. Greg A. WoodsNov 29, 2009
  2. Jeff KingNov 29, 2009
  3. Greg A. WoodsNov 30, 2009
  4. Dmitry PotapovNov 30, 2009
  5. Greg A. WoodsDec 1, 2009
  6. Dmitry PotapovDec 1, 2009
  7. Greg A. WoodsDec 1, 2009
  8. Dmitry PotapovDec 2, 2009
  9. Nanako ShiraishiDec 2, 2009
  10. Jeff KingDec 2, 2009
  11. Greg A. WoodsDec 3, 2009
  12. Junio C HamanoDec 3, 2009
  13. Greg A. WoodsDec 3, 2009
  14. Jeff KingDec 3, 2009
  15. Uri OkrentDec 3, 2009
  16. Marko KreenDec 3, 2009
  17. Greg A. WoodsDec 9, 2009
  18. Jeff KingDec 3, 2009
  19. Junio C HamanoNov 29, 2009
  20. Greg A. WoodsNov 30, 2009
  21. Junio C HamanoNov 30, 2009
  22. Dmitry PotapovNov 30, 2009
  23. Greg A. WoodsDec 1, 2009
  24. Dmitry PotapovDec 1, 2009
  25. Greg A. WoodsDec 1, 2009
  26. Dmitry PotapovDec 1, 2009
  27. Greg A. WoodsDec 1, 2009
  28. Dmitry PotapovDec 1, 2009
  29. Jeff EplerDec 1, 2009
  30. Greg A. WoodsDec 1, 2009
  31. Dmitry PotapovDec 2, 2009
  32. Greg A. WoodsDec 3, 2009
  33. Junio C HamanoDec 2, 2009

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.