LinuxCommandLibrary

git-commit-tree

Create a new commit object

TLDR

Create a commit object with the specified message

$ git commit-tree [tree] -m "[message]"
copy

Create a commit object reading the message from a file (use - for stdin)
$ git commit-tree [tree] -F [path/to/file]
copy

Create a GPG-signed commit object
$ git commit-tree [tree] -m "[message]" [[-S|--gpg-sign]]
copy

Create a commit object with the specified parent commit object
$ git commit-tree [tree] -m "[message]" -p [parent_commit_sha]
copy

SYNOPSIS

git commit-tree <tree> [-p <parent>]... [-m <message> | -F <file>] [--author=<author>] [--date=<date>]

PARAMETERS

<tree>
    The object name of the tree object that represents the content of the commit.

-p <parent>
    The object name of a parent commit object. Multiple parents can be specified for a merge commit.

-m <message>
    The commit message. Implies -S if gpg.commit.sign is set, and no explicit --no-gpg-sign is given.

-F <file>
    Read the commit message from the given file.

--author=<author>
    Override the author name and email address.

--date=<date>
    Override the commit date.

--no-gpg-sign
    Countermand commit.gpgSign in the config

DESCRIPTION

The git commit-tree command creates a new commit object. It takes a tree object as input, representing the state of the filesystem to be committed, and optionally one or more parent commit objects representing the commit history. The resulting commit object contains the tree, the parents, the author and committer information, and a commit message. This command is primarily used internally by Git tools to construct commits, often within scripting environments or advanced workflows where finer control over commit creation is needed.
Unlike `git commit`, git commit-tree does not modify the working directory or index. It only creates a new commit object in the object database. The user is responsible for managing the index, working directory, and updating branches to point to the new commit. This makes it suitable for low-level operations and scripts where direct manipulation of Git objects is necessary.

CAVEATS

This command does not update the index or working directory. It only creates a commit object. The user must manually update branches to point to the new commit if desired.

USAGE EXAMPLE

To create a commit from a tree object with a parent and a message:
`git commit-tree -p -m "My commit message"`

RETURN VALUE

The command prints object name of the newly created commit to stdout.

HISTORY

git commit-tree was introduced early in Git's development as a fundamental building block for creating commits programmatically. It provided a lower-level interface compared to git commit, enabling scripts and tools to construct commit objects directly. The command has remained relatively stable, focusing on core functionality with minimal changes over time. Its primary use continues to be within Git tooling and scripting environments rather than direct user interaction.

SEE ALSO

Copied to clipboard