# Automatic commit message template for Jujutsu

**URL:** https://discourse.nixos.org/t/automatic-commit-message-template-for-jujutsu/58492
**Category:** Development
**Created:** [January 8, 2025, 11:18am UTC](https://discourse.nixos.org/t/automatic-commit-message-template-for-jujutsu/58492 "2025-01-08T11:18:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![FliegendeWurst](https://discourse.nixos.org/user_avatar/discourse.nixos.org/fliegendewurst/32/3974_2.png) [@FliegendeWurst](https://discourse.nixos.org/u/FliegendeWurst)
#### Post date: [January 8, 2025, 11:18am UTC](https://discourse.nixos.org/t/automatic-commit-message-template-for-jujutsu/58492/1 "2025-01-08T11:18:57Z")

</div>

Commit messages in nixpkgs are often very predictable. Here is a way to automatically generate (parts of the) commit message for package changes.

First put this in your PATH as `gen-commit-message`:

```auto
#!/usr/bin/env bash
# requires: ripgrep, moreutils, jujutsu, vim (or other editor)
rm /tmp/commit_msg 2> /dev/null
for file in $(cat $1 | rg --only-matching -r '$1' "M (.+)"); do
  name=$(echo "$file" | rg --only-matching -r '$1' '([^/]+)/(package|default).nix')
  echo -n "$name: " >> /tmp/commit_msg
  jj diff --git -- "$file" | rg --only-matching -r '$1' 'version.*=.*"([^"]+)"' | xargs -L 2 sh -c 'if [[${#0} -ne 0 && ${#1} -ne 0]]; then echo $0 "->" $1; else echo ""; fi' >> /tmp/commit_msg
done
cat /tmp/commit_msg $1 | sponge $1
exec vim -c '1 | startinsert!' $1

```

Then you can execute `JJ_EDITOR=gen-commit-message jj split <file>` and the "package: " prefix of the commit message will be there already. If the version is updated, “old -\> new” is added with the right values.

---

<div class="post-metadata">

### Author: ![\_Andrew](https://discourse.nixos.org/user_avatar/discourse.nixos.org/_andrew/32/10331_2.png) [@\_Andrew](https://discourse.nixos.org/u/_Andrew)
#### Post date: [September 10, 2025, 6:28pm UTC](https://discourse.nixos.org/t/automatic-commit-message-template-for-jujutsu/58492/2 "2025-09-10T18:28:42Z")

</div>

I did [a similar thing](https://codeberg.org/AndrewKvalheim/configuration/src/commit/40ea4ae07cf95d99af031788aaf1150fbc2fcf99/common/resources/complete-git-commit-message.zsh), but as a shell completion:

```console
$ git commit --message ┃↹
# message
example-package: 1.2.3 → 2.0.0 -- Version change

```
