Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With git rebase, is there a way to reword commit messages in the git-rebase-todo using the default commands?

Tags:

git

git-rebase

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?

like image 650
buratino Avatar asked Mar 22 '15 18:03

buratino


People also ask

How do I change a commit message in rebase?

To change the most recent commit message, use the git commit --amend command. To change older or multiple commit messages, use git rebase -i HEAD~N . Don't amend pushed commits as it may potentially cause a lot of problems to your colleagues.

What is reword in git rebase?

"reword" allows you to change ONLY the commit message, NOT the commit contents. "edit" allows you to change BOTH commit contents AND commit message (the mechanism by which git allows you to edit the commit contents is by "pausing" the rebase; so you can amend the commit)

Does rebase rewrite commit history?

Changing older or multiple commits. To modify older or multiple commits, you can use git rebase to combine a sequence of commits into a new base commit. In standard mode, git rebase allows you to literally rewrite history — automatically applying commits in your current working branch to the passed branch head.


1 Answers

You can probably use the exec option to achieve what you want.

Use an exec command similar to git commit --amend -m "this is the new message"

You can either use that directly, or if you need more sophistication put it in an external script called my_reword.

#!/bin/sh git commit --amend -m "$1" 

Then add in the exec line wherever you want

pick 6b24464 foo pick a681432 Foo x my_reword "this is a new message" pick 8ccba08 foo foo 
like image 159
Andrew C Avatar answered Oct 11 '22 12:10

Andrew C