duckduckduck

joined 5 days ago
[–] duckduckduck@programming.dev 2 points 4 days ago* (last edited 4 days ago)

Thanks that is a great start, and even better gives me an excuse to faff about with scripting. I'll share what I come up with!

EDIT Oh interesting, in my debugging I found out that if you revert a revert now (git version 2.43.0) that the subject line reads "Reapply" instead of "Revert "Revert "..."""

Do you... like it?

And yeah I made an account just to ask this question. Hello! Nice looking server you've got here. 🖐

 

Whenever I do a git revert I go into an edit session with the following pre-filled.

Revert "wip: does this work?"

This reverts commit ad21a2ae23166b3f3cddoooooooom94821e3cdb4.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
...

...and so on.

I like to use conventional commits, so I change this to revert: "wip: does this work?".

Is there a way to get the initial template for the revert commit message to appear this way by default? Lowercase, and with a colon.


UPDATE This is what I came up with

#!/bin/bash

COMMIT_MSG_FILE=$1

old_subject_line=$(head -1 $COMMIT_MSG_FILE)

# Not a revert
if [[ ! "$old_subject_line" =~ ^Revert\ \" ]]
then
    exit 0
fi

new_subject_line=$(echo $old_subject_line|sed 's/^Revert/revert:/')

sed -i "1s/.*/$new_subject_line/" $COMMIT_MSG_FILE

Curiously, the case where two "Reverts" in a row become a "Reapply" doesn't come up like I thought it would. Maybe it only happens if you use the default Revert "yada yada yada" subject line.