Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically reword all rebased commits

Tags:

git

bash

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?

like image 705
Bryce Drew Avatar asked Jul 06 '16 21:07

Bryce Drew


1 Answers

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.

like image 80
λuser Avatar answered Oct 12 '22 22:10

λuser