Git Reference ยท Plumbing Commands
git commit-tree command
Reference for git commit-tree: create a commit object from a tree ID, set parents with -p, pass the message with -m or stdin, and move a branch to the result.
git commit-tree creates a commit object from an existing tree, optional parent commits and a message, and prints the new commit's ID. It does exactly that and nothing more: no index is read, no branch is moved, HEAD is untouched. The new commit is unreachable until you point a ref at it.
Porcelain git commit is essentially "write-tree, then commit-tree with the current HEAD as parent, then update-ref". Using commit-tree directly is handy in scripts that rewrite history, import data or build synthetic commits.
git commit-tree <tree> [-p <parent>]... -m <message> echo "message" | git commit-tree <tree> -p <parent>
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
git commit-tree [(-p <parent>)...] [-S[<keyid>]] [(-m <message>)...] [(-F <file>)...] <tree>
| Name | Description |
|---|---|
<tree> |
The tree object ID (or a tree-ish such as HEAD^{tree}) to record. |
-p <parent> |
A parent commit. Repeat for merge commits. Omit for a root commit. |
-m <message> |
The message. Repeated -m options become separate paragraphs. |
-F <file> |
Read the message from a file (- for stdin). |
-S[<keyid>] |
GPG-sign the commit. |
--no-gpg-sign |
Do not sign, even if commit.gpgSign is set. |
Returns: the ID of the new commit on standard output.
Errors: a fatal error (exit code 128) if an object does not exist, if the tree argument is a commit (use HEAD^{tree}, not HEAD), or if a parent is not a commit. If no -m or -F is given, the message is read from standard input.
Usage notes
- Author and committer come from
GIT_AUTHOR_*andGIT_COMMITTER_*(oruser.nameanduser.email). Set the date variables to get reproducible IDs. - Nothing points at the commit. Run
git update-reforgit branch -fafterwards, otherwisegit gcwill eventually remove it. - Parents are not checked for ancestry. You may give any commit as a parent, including unrelated ones; that is how histories are grafted together.
- Empty commits are fine. Passing the parent's own tree creates a commit with no changes; porcelain
git commitrefuses that without--allow-empty. - Message encoding: the message is stored exactly as given. A trailing newline is added if it is missing.
- Signed commits add a
gpgsigheader. See signing and security.
Related
git write-tree,git mktree,git update-ref,git cat-file- Lessons: Git objects, Commits