39

I remember that for about a year ago I did some merges that resulted in the commit messages being Merge branch 'Name_of_branch' on the remote repository.

From what I remember it would happen if I rebased all commits in a branch and then merged it to master and then pushed to remote repository.

But now I can't reproduce it with git-1.7.2.2.

Have it been fixed? Or can someone explain how this happens, and perhaps how to avoid it?

Sandra Schlichting
  • 25,050
  • 33
  • 110
  • 162
  • 18
    `$ git merge --ff-only --no-commit Name_of_branch` - does the the merge if fast-forward is possible and spares that message. – hakre Dec 25 '13 at 19:18

3 Answers3

42

That's a default merge commit message. It doesn't take anything special to get it - just do any nontrivial merge into master:

- o - o - X (master)
   \     /
    o - o (topic)

The default commit message for commit X will be "Merge branch 'topic'". If you merge into a branch other than master, the default message is "Merge branch '<merged-branch>' into '<branch>'".

I'm not sure why you're asking about "fixing" and "avoiding" this. It's a very reasonable default message for a merge commit. If you'd like a more detailed merge commit message, you're certainly welcome to provide one. (The two primary ways are to use git merge --no-commit followed by git commit, or git merge followed by git commit --amend to edit the message.)

Perhaps you're used to doing only fast-forward merges? (Those are trivial merges, where the commit you're merging has your current branch as ancestor, so all git has to do is move the branch forward through history.) Those don't generate merge commits, so there's no commit message.

(By the way, pushing has nothing to do with this - all it does is copy information from one repo to another. It doesn't ever create commits.)

Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • 6
    Awesome! Thank you very much! The reason I talked about "fixed" and "avoid" is that Linus says in this talk, that the default merge message was the only design flaw in git, but now it was too late to fix it, as people have gotten used to it. See the video at http://video.linuxfoundation.org/video/1578 If you download it, you can fast forward. I think it is towards the end he says it. Perhaps in the Q&A. – Sandra Schlichting Aug 29 '10 at 16:06
  • @Sandra: Ah, I see where you're coming from. I don't have time to watch the video now, but I'm guessing the idea is that it's a bad idea to embed branch information in commit messages, and it's bad to provide auto-accepted default commit messages. The message is still a pretty reasonable default, if your branches and workflow are good, I think (e.g. git.git) - but yeah, editing/amending it is probably often a good idea. – Cascabel Aug 29 '10 at 16:12
  • Just came across this issue as well. Great to know I can append to the previous message. One reason for why one would like to add their own custom message is to reference a bug Id / review board identifier to document an 'approved' merge. – jdknight Sep 27 '13 at 21:59
  • @SandraSchlichting, that video link is broken; is there any chance you know the title of the talk or another way to find it? – Wildcard Mar 18 '16 at 07:00
  • 1
    Old thread, but https://youtu.be/8ET_gl1qAZ0?t=1h7m21s. Talk was seemingly called "Linus Torvalds – An Advanced Git Tutorial." – James Skemp Jul 24 '17 at 19:59
6

git merge -m

I am using git 1.7.8

Unknown
  • 5,722
  • 5
  • 43
  • 64
user3770488
  • 61
  • 1
  • 1
5

I don't mind the automatic message, but I did want to avoid having to exit my editor just to keep the default. The following option achieves that behavior (in a script of mine):

GIT_MERGE_AUTOEDIT=no git merge origin/master
bradoaks
  • 1,112
  • 10
  • 12