-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Low
-
None
-
Affects Version/s: 3.4.31
-
Component/s: General
-
None
-
Severity 3 - Minor
Hi Sourcetree Team,
I found two issues with Git commit templates in Sourcetree for Windows.
Environment
- Sourcetree for Windows: 3.4.31
- Operating system: Windows
- Git backends tested:
- System Git
- Embedded Git
- libgit2: tested disabled
- Git commit template configured globally and locally
Summary
Sourcetree does not initially display a Git commit template for repositories that were already registered in Sourcetree when commit.template was configured.
The same template works correctly when committing from the command line.
After manually changing DraftCommitMsg in one repository's sourcetreeconfig.json file and restarting Sourcetree, the commit template was detected. After this action, commit templates also started working in the other registered repositories.
Additionally, Sourcetree removes template comment lines starting with # before displaying the template in the commit message field. This differs from command-line Git behavior and prevents users from seeing instructions contained in the template.
Git configuration
Global configuration:
commit.template=C:/Users/<user>/.gitmessage
Repository-local configuration was also tested:
commit.template=.gitmessage
Git reports both settings correctly:
global file:C:/Users/<user>/.gitconfig C:/Users/<user>/.gitmessage local file:.git/config .gitmessage
The local configuration takes precedence, and both referenced template files exist.
The following configurations are not explicitly set:
commit.cleanup core.commentChar core.editor sequence.editor
Issue 1: Existing repositories do not detect the commit template
Steps to reproduce
- Register and open one or more repositories in Sourcetree.
- Ensure that commit.template is not configured yet.
- Configure a global Git commit template:
git config --global commit.template "C:/Users/<user>/.gitmessage"
- Verify that the configuration is effective:
git config --show-origin --show-scope --get-all commit.template
- Verify that the template works from the command line:
git commit
- Close and restart Sourcetree.
- Open the commit view of a repository that was already registered.
- Inspect the commit message field.
Actual result
The commit message field is empty. The configured Git commit template is not displayed.
The behavior is unchanged when using System Git, Embedded Git, or when disabling libgit2.
Expected result
Sourcetree should detect the current effective commit.template configuration and populate the commit message field with the configured template.
This should also work when commit.template is configured or changed after the repository was added to Sourcetree.
Observed workaround
The repository's sourcetreeconfig.json contained:
"DraftCommitMsg": ""
With Sourcetree closed, I manually changed DraftCommitMsg to an arbitrary non-empty string.
After saving the file and restarting Sourcetree, Sourcetree replaced that value with the configured Git commit template.
After this one-time modification, commit templates also started working in the other repositories registered in Sourcetree. No further changes to the template files or Git configuration were required.
Suspected cause
Sourcetree may cache the draft commit message or the absence of a commit template for repositories that were opened before commit.template was configured.
The effective Git configuration may only be reevaluated after DraftCommitMsg changes or another internal refresh is triggered.
This is an observation based on the workaround. The exact internal cause is unknown.
Issue 2: Template comments are removed before editing
Git commit templates can contain comment lines starting with #. These lines may provide important instructions and guidance for writing the commit message.
Example template
<type>[optional scope][!]: <description>
[optional body]
[optional footer(s)]
# BREAKING CHANGE: <description>
# Types:
# build Build system or external dependencies
# chore Maintenance not covered by another type
# ci CI/CD configuration and scripts
# docs Documentation only
# feat New or extended functionality
# fix Bug fix
# perf Performance improvement
# refactor Code change without new behavior or bug fix
# revert Revert a previous commit
# style Formatting without behavioral changes
# test Add or correct tests
Command-line behavior
When running git commit from the command line, the editor displays the complete template, including all comment lines starting with #.
The user can read these instructions while writing the commit message.
When the commit is created, Git removes the comment lines from the final commit message.
This is the expected behavior:
- Template comments are visible while editing.
- Template comments provide guidance to the user.
- Template comments are not included in the resulting commit message.
- The final commit message remains clean.
Sourcetree behavior
In Sourcetree, comment lines starting with # are removed before the template is displayed in the commit message field.
As a result, users cannot see the instructions contained in the template comments while composing the commit message.
Expected result
Sourcetree should match the command-line Git behavior:
- Display the complete commit template, including comment lines starting with #, while the user edits the commit message.
- Preserve the comments as visible guidance in the commit editor.
- Remove the comment lines only when the commit is created.
- Do not include template comments in the final commit message.
Requested fixes
Please update Sourcetree so that it:
- reads the effective commit.template setting when opening a repository;
- detects changes to global and repository-local commit.template settings;
- refreshes an empty or stale DraftCommitMsg when appropriate;
- does not require manual modification of sourcetreeconfig.json;
- handles existing and newly added repositories consistently;
- displays the complete template, including comment lines starting with #, in the commit editor;
- applies Git's normal commit-message cleanup only when the commit is created;
- produces the same effective behavior as git commit on the command line.
Thank you for looking into this.
Kind regards,
Stefan