-2

Update

My company adds a prefix to the commit history which i had gotten so used to, I didn't see it but of course git would, and that was causing the issue. Removing that prefix fixed my issue.

Example:

kth-JAN-1614-ui-nits fixup! kth-JAN-1614-ui-nits Refactor and small improvements [Karthik Thirugnanam] 

The hook adds that kth-JAN-1614-ui-nits prefix to the commit summary.

It works again if I disable hooks:

git commit --no-verify --fixup 

Original

I am trying to get the fixup/autosquash flow to work but it doesnt seem to work for me, though it seems to have been introduced ages ago..

My repo log

* 4f9429d8 Tue Jun 24 16:13:44 2025 (12 minutes ago ) (HEAD -> kth-JAN-1614-ui-nits) kth-JAN-1614-ui-nits fixup! kth-JAN-1614-ui-nits Refactor and small improvements [Karthik Thirugnanam] * b9f50337 Tue Jun 24 15:57:02 2025 (29 minutes ago ) (origin/kth-JAN-1614-ui-nits) kth-JAN-1614-ui-nits Log SQL statement in Marten logger [Karthik Thirugnanam] * 6f376eca Tue Jun 24 15:52:55 2025 (33 minutes ago ) kth-JAN-1614-ui-nits UI Nit fixes for release pipelines [Karthik Thirugnanam] * c071b3c2 Tue Jun 24 15:50:56 2025 (35 minutes ago ) kth-JAN-1614-ui-nits Refactor and small improvements [Karthik Thirugnanam] * 
> git -v git version 2.39.1.windows.1 

Rebase invocation

> git rebase -i --autosquash origin/master 

Rebase

pick c071b3c2 kth-JAN-1614-ui-nits Refactor and small improvements pick 6f376eca kth-JAN-1614-ui-nits UI Nit fixes for release pipelines pick b9f50337 kth-JAN-1614-ui-nits Log SQL statement in Marten logger pick 4f9429d8 kth-JAN-1614-ui-nits fixup! kth-JAN-1614-ui-nits Refactor and small improvements 

From what I see, the last commit should be reordered and marked as fixup?

4
  • “this one was resolved in a way less likely to help future readers.” Using a hook that changes the subject of e.g. fixup! commits and makes --autosquash fail is relevant to others. Commented Jun 26 at 14:38
  • @Guildenstern That means there is insufficient information in the question itself, which means it should remain closed. Commented Jun 27 at 19:33
  • @MarkRotteveel Then I can add the missing information to the question based on the answer from the OP. Is that ok? Commented Jun 27 at 19:50
  • 1
    @Guildenstern I think that would be good. You'll have my reopen vote for sure. Commented Jun 27 at 21:02

2 Answers 2

1

The issue seems to be that the pre-commit hook adds the branch name as the subject prefix for some reason. Something like this:

# .git/hooks/commit-msg set -u msg="$1" ( git branch --show-current | tr '\n' ' ' cat "$msg" ) | sponge "$msg" 

Here I use the commit-msg hook which is the hook designed for that purpose.

You encounter the problem when you run e.g. git commit --fixup=@. Because you get this:

JIRA-OFFICIAL-65498798745-fix-issue fixup! Perfect solution 

Now you can’t autosquash because the fixup! won’t be detected.

You can detect this case in the script and stop the prefixing for these automation commits.

#!/usr/bin/env bash set -u msg="$1" subject=$(head -1 "$msg") subject_start="${subject:0:7}" # Ignore if this is an amend commit if test "$subject_start" = 'fixup! ' \ || test "$subject_start" = 'amend! ' \ || test "$subject_start" = 'squash!' \ || test "$subject_start" = 'reword!' then exit 0 fi ( git branch --show-current | tr '\n' ' ' cat "$msg" ) | sponge "$msg" 

Or with regular shell:

#!/bin/sh set -u msg="$1" subject=$(mktemp) head -1 "$msg" >"$subject" # Ignore if this is an amend commit if git grep --quiet --no-index \ -e '^fixup!' -e '^squash!' \ -e '^amend!' -e '^reword!' -- "$subject" then exit 0 fi ( git branch --show-current | tr '\n' ' ' cat "$msg" ) | sponge "$msg" 
Sign up to request clarification or add additional context in comments.

1 Comment

Getting maybe-excessively vanilla with it, branch=`git branch --show-current`; while read -r w1 rest; do case $w1 in *!) echo $w1 $rest;; *) echo $branch $w1 $rest;; esac; cat; done <"$1" >"$1".new; mv "$1".new "$1";
-2

It is likely my companies hook that adds a prefix to the commit message.

Edit: Leaving this here.. My company adds a prefix to the commit history which i had gotten so used to, i didnt see it but of course git would, and that was causing the issue. Removing that prefix fixed my issue.

I used git commit --no-verify --fixup to ensure the precommit hooks are skipped for this kind of commit.

1 Comment

BTW, the pre-commit hook isn't meant to modify the commit message, but only to verify that the commit is "good".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.