# Using ts-node
npx ts-node <path/to/git.ts> commit <message>
# Using node
node <path/to/git.js> commit <message>
-
message
Use the given
message
as the commit message.
Record changes to the repository.
-
First get the current branch name and the reference to the latest commit if present. This is handled by the functions
getCurrentBranchName()
andgetBranchHeadReference()
respectively. The current branch name is stored in the.git/HEAD
file, and the reference is present at the location.git/refs/heads/<branch>
. The reference might not be there if there were no previous commits. -
Next, create and store the Tree object from current state of the index file and get the hash.
-
Next build a store a Commit object using the tree hash from Step 2 and parent hash (if any) from Step 1.
-
Finally update the head reference.