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

Re: [PATCH] have merge put FETCH_HEAD data in commit message

From
Junio C Hamano <junkio@cox.net>
Date
Mar 21, 2007, 15:37 UTC
Message-ID
<7v648u38ws.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20070321120643.GI20583@mellanox.co.il>
"Michael S. Tsirkin" <mst@dev.mellanox.co.il> writes:
Show 19 quoted lines
> Hi!
> I often like to fetch some code from others, review and
> then merge. So:
>
> git fetch <URL>
> git log -p FETCH_HEAD
> git merge FETCH_HEAD
>
> which is all good but gets me this message in commit log:
>
>     Merge commit 'FETCH_HEAD' into master
>
> which is not very informative.
> I can always fix this up with git commit --amend, but
> I'd like to avoid the extra step.
>
> Would the following patch be appropriate?
>
> Signed-off-by: Michael S. Tsirkin <mst@dev.mellanox.co.il>

Would "Hi!" and "Would the following be appropriate?" be part of the final commit log message?

I often hear from people who seems to like "fetch & merge", instead of "pull & reset ORIG_HEAD", as a workflow to avoid undesirable merging. This might largely be a matter of taste, but from philosophical point of view, fetch & merge is a sign of distrust (your default is not to merge, and you merge only when you choose to), and pull & reset is the opposite (your default is to merge, and after you inspect you may choose not to merge). Tool support to encourage the former feels somewhat wrong.

Having said that, since that comes up every now and then, I suspect it might make sense to have an optional behaviour in "git pull" that lets you say...

	$ git pull --preview $URL $refspec
which runs the following:
	. git fetch
        . git log -p `sed -e '/	not-for-merge	/d'\
        .	-e 's/	.*//' $GIT_DIR/FETCH_HEAD` \
        .	--not HEAD
	. asks you if you want to conclude this with a merge
	. git merge if told, otherwise abort.

The "git-log" above reads "give me the commits that are reachable from commits that are scheduled for merge but not in the current HEAD", i.e. the ones that will get merged.

Show 15 quoted lines
> diff --git a/git-merge.sh b/git-merge.sh
> index 8759c5a..629611b 100755
> --- a/git-merge.sh
> +++ b/git-merge.sh
> @@ -108,6 +108,10 @@ merge_name () {
>  		git-show-ref -q --verify "refs/heads/$truname" 2>/dev/null
>  	then
>  		echo "$rh		branch '$truname' (early part) of ."
> +	elif test -r "$GIT_DIR/$remote"
> +	then
> +		echo -n "$rh		"
> +		grep -v not-for-merge "$GIT_DIR/$remote"
>  	else
>  		echo "$rh		commit '$remote'"
>  	fi

This 'not-for-merge' grep is only good while merging FETCH_HEAD, and will not work for any other random stuff in "$GIT_DIR", so at least it should be more specific, not just checking if it is the name of a readable file in $GIT_DIR. Somebody might find good usecases for doing "git merge ORIG_HEAD" or "git merge refs/bases/tutorial", for example, and your echo & grep would do something "interesting".

Every time I added "echo -n" from my sloppiness, somebody sent in a patch to replace it with "printf". I think people on non Linux platforms would hate you for using "echo -n" (I should bug Tytso about this with git-mergetool).

I am not sure what you meant by echo -n and grep -v. Other codepaths in the if-else chain seems to create $rh (the value of the single commit being merged) followed by two tabs followed by the message, and each line in $GIT_DIR/FETCH_HEAD is already in that format, so I suspect your code duplicates the commit object name twice?

Even when you fetch more than one branch in FETCH_HEAD, using FETCH_HEAD as an SHA-1 expression always picks up the object name on the first line (iow "git merge FETCH_HEAD" will not create an Octopus), so grepping for lines without not-for-merge marker is not correct either.

You would probably want something like:
		...
	elif test FETCH_HEAD = "$remote" && test -r "$GIT_DIR/FETCH_HEAD"
        then
        	sed -e 's/	not-for-merge	/		/' \
		    -e 1q "$GIT_DIR/FETCH_HEAD"
	else
        	...
Previous: Michael S. TsirkinNext: Michael S. Tsirkin
Message 2 of 70 in “have merge put FETCH_HEAD data in commit message”
  1. have merge put FETCH_HEAD data in commit messageMichael S. Tsirkin, Mar 21, 2007
  2. Junio C HamanoMar 21, 2007
  3. Michael S. TsirkinMar 22, 2007
  4. Junio C HamanoMar 22, 2007
  5. Michael S. TsirkinMar 22, 2007
  6. Junio C HamanoMar 22, 2007
  7. Michael S. TsirkinMar 22, 2007
  8. Junio C HamanoMar 22, 2007
  9. Michael S. TsirkinMar 22, 2007
  10. Junio C HamanoMar 22, 2007
  11. Michael S. TsirkinMar 22, 2007
  12. Junio C HamanoMar 24, 2007
  13. Michael S. TsirkinApr 4, 2007
  14. Junio C HamanoApr 4, 2007
  15. Michael S. TsirkinApr 4, 2007
  16. Shawn O. PearceApr 4, 2007
  17. Junio C HamanoApr 4, 2007
  18. Shawn O. PearceApr 4, 2007
  19. Junio C HamanoApr 4, 2007
  20. display shortlog after git-commitMichael S. Tsirkin, Apr 4, 2007
  21. Junio C HamanoApr 4, 2007
  22. display shortlog after git-commitMichael S. Tsirkin, Apr 15, 2007
  23. Junio C HamanoApr 15, 2007
  24. display the subject of the commit just madeMichael S. Tsirkin, Apr 16, 2007
  25. Junio C HamanoApr 16, 2007
  26. Michael S. TsirkinApr 16, 2007
  27. Junio C HamanoApr 16, 2007
  28. Michael S. TsirkinApr 16, 2007
  29. Junio C HamanoApr 16, 2007
  30. Michael S. TsirkinApr 16, 2007
  31. Michael S. TsirkinApr 16, 2007
  32. Junio C HamanoApr 16, 2007
  33. Shawn O. PearceApr 16, 2007
  34. Michael S. TsirkinApr 16, 2007
  35. Alex RiesenApr 16, 2007
  36. Junio C HamanoApr 16, 2007
  37. Michael S. TsirkinApr 16, 2007
  38. Junio C HamanoApr 16, 2007
  39. Michael S. TsirkinApr 16, 2007
  40. remove shortlog from git-commit outputMichael S. Tsirkin, Apr 16, 2007
  41. Julian PhillipsApr 16, 2007
  42. Michael S. TsirkinApr 16, 2007
  43. Julian PhillipsApr 16, 2007
  44. Michael S. TsirkinApr 17, 2007
  45. Julian PhillipsApr 17, 2007
  46. Junio C HamanoApr 4, 2007
  47. Michael S. TsirkinApr 15, 2007
  48. Junio C HamanoApr 15, 2007
  49. Michael S. TsirkinApr 15, 2007
  50. Andy ParkinsApr 15, 2007
  51. Michael S. TsirkinApr 15, 2007
  52. wt-status: show author info if status.showauthor is setJeff King, Apr 4, 2007
  53. Junio C HamanoApr 4, 2007
  54. Michael S. TsirkinApr 4, 2007
  55. Junio C HamanoApr 4, 2007
  56. Shawn O. PearceApr 4, 2007
  57. Jakub NarebskiApr 4, 2007
  58. Jakub NarebskiMar 23, 2007
  59. J. Bruce FieldsMar 23, 2007
  60. Jakub NarebskiMar 23, 2007
  61. J. Bruce FieldsMar 23, 2007
  62. Jakub NarebskiMar 24, 2007
  63. Put FETCH_HEAD data in merge commit messageMichael S. Tsirkin, Mar 22, 2007
  64. Junio C HamanoMar 22, 2007
  65. Jeff KingMar 22, 2007
  66. Junio C HamanoMar 22, 2007
  67. Jeff KingMar 22, 2007
  68. Andy ParkinsMar 22, 2007
  69. [PATCHv2] put FETCH_HEAD data in merge commit messageMichael S. Tsirkin, Mar 21, 2007
  70. Junio C HamanoMar 21, 2007

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.