Get current commit id of Git and update to package.json
- Tan Shuai
- Software Development
- 21 Aug, 2021
When developing a Node.js project, you may want to keep track of the current commit ID of your Git repository. This information can be useful for debugging, versioning, or deployment purposes. One way to achieve this is by updating the package.json
file with the current commit ID during the build process. This article will guide you through the steps to get the current commit ID of Git and update it to the package.json
file using Node.js.
"predev": "node ./node_modules/json/lib/json.js -I -f package.json -e \"this.commit='$(git rev-parse --short HEAD)'\"",