I want to automatically output the commit ID to the file when I commit.

Asked 2 years ago, Updated 2 years ago, 174 views

We are currently using VSCode for Git management.

During management, the commit ID is printed as shown in the attached image, but I would like to automatically output the commit ID to a text file at the same time as the commit.Is this possible?
If possible, please let me know how to do it.

src=

Using the URL below, I understood that using commands such as $git log-n1--pretty=format:"%H">commitID.txt can print the commit ID to a text file.

File output of the commit ID of the current branch

However, I am troubled because I cannot automatically print the commit ID to a text file as soon as I commit.(For the above method, you will need to open git bash and fill in the code)

Could you tell me how to output automatically?

VSCode is not the only editor to use if it is possible to automatically output a commit ID to a text file when you commit a file to a repository.
(GitHub, Git Bash, GitLab, etc.)
The output location of the text file is also not specified.

I look forward to hearing from you.

git git-bash

2022-09-29 22:30

1 Answers

It's easy to implement with hooks.

Create a post-commit in .git/hooks/ and write:
After committing, post-commit is invoked.

#!/bin/sh

git log-n1 --pretty=format: "%H" >>commitID.txt


2022-09-29 22:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.