Skip to content

commit-tree Git Command Guide

The git commit-tree command creates a new commit object using an existing tree object, which can be thought of as a snapshot of the working directory, and an optional commit message.

Terminal window
git commit-tree <tree> [(-p <parent>) ...] [-m <message>] [(-F <file>) ...] [-S[<keyid>]] [--no-gpg-sign] [--gpg-sign[=<key-id>]] [--author <author>] [--date <date>] [--verify]
OptionDescription
-p , —parent=Use SHA-1 of parent commit
-m , —message=Use given message as commit message
-F , —file=Read commit message from given file
—author Override author information
—date Override the author date
—verifyVerify commit object
—no-gpg-signDon’t GPG-sign the commit
—gpg-sign[=]GPG-sign the commit
-S[]GPG-sign the commit
ParameterDescription
SHA-1 of the tree object to be committed
SHA-1 of parent commit(s)
Terminal window
echo "Initial commit" | git commit-tree <tree-sha>

Creates a new commit object using the specified tree SHA.

Terminal window
echo "Add feature" | git commit-tree -p <parent-sha> <tree-sha>

Creates a commit with one parent.

Terminal window
echo "Merge branches" | git commit-tree -p <parent1> -p <parent2> <tree-sha>

Creates a merge commit with two parents.

Terminal window
git commit-tree -F commit-msg.txt -p HEAD <tree-sha>

Uses message from file for the commit.

Terminal window
git commit-tree --author "Name <email>" -m "Fix bug" -p HEAD <tree-sha>

Creates commit with specified author.

Terminal window
git commit-tree -S -m "Signed commit" -p HEAD <tree-sha>

Creates a GPG-signed commit.

Terminal window
TREE=$(git write-tree)
echo "Tree commit" | git commit-tree $TREE

First creates a tree object, then commits it.

Terminal window
git commit-tree --verify -m "Verified commit" -p HEAD <tree-sha>

Creates commit and verifies its integrity.

To create a new commit object, use:

Terminal window
git commit-tree <tree-sha>

To create a commit with a parent, run:

Terminal window
git commit-tree -p <parent-sha> -m "Message" <tree-sha>

To create a merge commit, execute:

Terminal window
git commit-tree -p <parent1> -p <parent2> -m "Merge" <tree-sha>

How can I read commit message from a file?

Section titled “How can I read commit message from a file?”

To read commit message from a file, use:

Terminal window
git commit-tree -F <file> -p <parent> <tree-sha>

To sign a commit with GPG, run:

Terminal window
git commit-tree -S -m "Message" -p <parent> <tree-sha>

Applications of the git commit-tree command

Section titled “Applications of the git commit-tree command”
  1. Creating commits programmatically in scripts and automation
  2. Building custom Git workflows and tools
  3. Implementing advanced rebasing or merging operations
  4. Developing Git-compatible version control systems
  5. Debugging repository issues at the object level
  6. Supporting integration with external version control systems