Is it possible to run git commit-msg from previous commits?

I have a commit-msg hook that I run for all my local commits, and I have to be running for a specific project. The problem is that when I retract from other forks, some of my compatriots did not run this commit-msg hook. Today i'm doing

$ git rebase --interactive $commit_parent 

as described here is very similar here . Select commits that have not been executed properly, re-edit, and so on. All very functional, but also tedious, as I do it manually.

How can I automate this? The hook does not require control.

+4
source share
2 answers

This can be done automatically using a custom editor:

 #!/bin/bash # Save to rebase_editor.sh, chmod +x it file="$1" if head -n1 "$file" | egrep -q '^pick' "$file" ; then perl -pi -e 's/^pick/r/' "$file" fi 

and then do:

 GIT_EDITOR=./rebase_editor.sh git rebase -i <some-rev> 

On the first call, our โ€œeditorโ€ will receive a list of rebase -i from rebase -i , where it will change each pick to r (which is equal to reword ). In this mode, git will immediately start calling our โ€œeditorโ€ with a message about each re-committed commit (and without any pauses, which are usually performed in pick mode, where you can change the fix itself).

+2
source

I suppose this is very simple, given the description of the hook in the "hooks" man page:

 It takes a single parameter, the name of the file that holds the proposed commit log message. 

Just run the hooks script for each commit:

 git rev-list HEAD |while read h; do git show --format='%B' $h > tmp && sh .git/hooks/commit-msg.sample tmp done rm tmp 
0
source

All Articles