8

I want to be able to touch up my commit messages before I push them to my remote, but I want to automatically do that.

I can reword all my additional commits by doing

git rebase -i origin/master

This brings up an editor where I can change all the commits from pick to reword. Then it will bring up editors where I can touch up my commit messages.

Summary of constraints:

  • I don't want to have to change every commit to reword.
  • I don't want to manually type in every commit hash.

Is there a way to do rebase like this?

Bryce Drew
  • 5,777
  • 1
  • 15
  • 27
  • Are you trying to make the same change to each message? Maybe an example would be helpful. – Tom Fenech Jul 06 '16 at 21:36
  • I want to utilize the reword functionality without having to interactively rebase. I will edit my question for clarity – Bryce Drew Jul 06 '16 at 21:37
  • In case the rewording is intended to be automated rather than manual, `git filter-branch` might be the answer, see this question and response: https://stackoverflow.com/a/37941403/2184166 – ob-ivan Jul 24 '23 at 11:10

2 Answers2

14

Since the question is a bit vague on the nature of edits, these are just cues on what you could do.

I don't want to have to change every commit to reword.

You could change the editor used by git-rebase -i with git config sequence.editor 'sed -i s/pick/reword/', so that no editor pops for the rebase-todo, and picks are replaced. But that's a bit clumsy because you have to cancel the config after. (there's also core.editor for other cases, and $EDITOR).

You can also run git rebase origin/master -x 'git commit --amend'. -x adds a exec <argument of the -x>, line after each pick in the rebase-todo. Note there's no -i needed here. The amend will allow you to change the commit message, for example git commit --amend -m "new message".

I don't want to manually type in every commit I want to reword the message of.

You can use the EDITOR variable to a non-interactive command that edits in the way you want, but I don't know which kind of editing you want to do.

I want to rebase all the new commits with something other than pick

See previous answers.

λuser
  • 893
  • 8
  • 14
  • 1
    This is perfect `git rebase -i origin/master -x 'git commit --amend'` – Bryce Drew Jul 06 '16 at 21:44
  • 1
    Thank you, I didn't know about the `-c` (edit your comment though, there's an extra `config` after `-c`) – λuser Jul 06 '16 at 22:07
  • 3
    @λuser Instead of dong a permanent config, you can do `git -c sequence.editor='sed -i s/pick/reword/' rebase -i`. This removes the clumsiness of your answer completely. You can even try this alias git config alias.reword '-c sequence.editor="sed -i s/pick/reword/" rebase -i' – Joseph K. Strauss Jul 07 '16 at 15:48
0

I looked here so that I could do the same thing. I have a feature, written as multiple commits, basically small backups during development. I subsequently want to divide it up into two smaller features and so label each commit "Feature A: ..." and "Feature B: ..." before sorting the commits and creating separate branches for each feature.

After reading this thread I opted for the simple find and replace solution in my editor.

enter image description here

Ivan
  • 41
  • 4