Suppose I run git rebase -i HEAD~3
pick 6b24464 foo
pick a681432 Foo
pick 8ccba08 foo foo
# Rebase 960c384..8ccba08 onto 960c384
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
I would like to reword commit messages directly from this file, rather than editing each commit message one at a time (as per usual with reword
), like so:
reword 6b24464 foo bar
reword a681432 Foo Bar
reword 8ccba08 foo foo bar bar
# Rebase 960c384..8ccba08 onto 960c384
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
I had hoped that this could be done using just reword
or edit
, but I can't seem to figure out how (if even possible). I've been able to achieve the same result with
x git cherry-pick 6b24464 && git commit -amend "foo bar"
However, this is more time consuming than I'd like for large rebases. Any ideas?
I do not believe that can be done, because when you do a git rebase -i
you get only the first line of each commit message, not the full commit message.
As a convention, a commit message should have the first line be only a summary, and have more details about the change in the following lines. Here's Linus Torvalds on how to write a proper commit message
Also, please write good git commit messages. A good commit message looks like this:
Header line: explain the commit in one line (use the imperative) Body of commit message is a few lines of text, explaining things in more detail, possibly giving some background about the issue being fixed, etc etc. The body of the commit message can be several paragraphs, and please do proper word-wrap and keep columns shorter than about 74 characters or so. That way "git log" will show things nicely even when it's indented. Make sure you explain your solution and why you're doing what you're doing, as opposed to describing what you're doing. Reviewers and your future self can read the patch, but might not understand why a particular solution was implemented. Reported-by: whoever-reported-it Signed-off-by: Your Name <youremail@yourhost.com>
where that header line really should be meaningful, and really should be just one line. That header line is what is shown by tools like gitk and shortlog, and should summarize the change in one readable line of text, independently of the longer explanation. Please use verbs in the imperative in the commit message, as in
Fix bug that...
,Add file/feature ...
, orMake Subsurface...
So, even though you may have done only one line of message per commit, this is not what git is assuming, so it won't let you edit a commit message through a "one line per commit view".