Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to git commit --fixup=amend while changing the commit message non-interactively?

Tags:

git

git-commit

I want to squash some commit through scripting using git commit --fixup, but I have got stuck on the fact that the -m switch for messages cannot be used with --fixup:amend.

$ git commit --fixup=amend::/'Upgrade to foo' -m "Upgrade to bar"
fatal: options '-m' and '--fixup:amend' cannot be used together

(I would later git rebase --autosquash <some-much-earlier-commit> to squash them all together if I could get that far)

I could use the plain --fixup without amend but then I cannot change the commit message. Without the -m message, the editor opens for editing the commit message, so this cannot be done through scripting.

I understand that these are "porcelain" commands, but as I am doing this through scripting, I was wondering if there is still a way of doing the equivalent of git commit --fixup=amend while still changing the commit message non-interactively using "plumbing" commands?

like image 748
paradroid Avatar asked Jun 19 '26 00:06

paradroid


1 Answers

Git will create a new commit based on your git commit --fixup=amend:... command. You can create this commit yourself:

git commit -m "amend! <commit hash / old commit message>" -m "new commit message"

so for your given example it would be

git commit -m "amend! Upgrade to foo" -m "Upgrade to bar"

Note: the second -m parameter will fill the description. Alternatively when using an editor, you can put the second -m argument on the third line:

amend! Upgrade to foo

Upgrade to bar

See: How to commit a change with both "message" and "description" from the command line?

like image 70
Dr_DragonKiller Avatar answered Jun 20 '26 14:06

Dr_DragonKiller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!