What is the difference between git commit and git commit-tree

I read about git objects: blob, tree, commit, tag. To better understand how git works, I tried a low level command like write-tree and commit-tree .

  • mkdir test; cd test mkdir test; cd test git init
  • I am creating a file and git add file . I see the blob and tree object being generated in .git/objects
  • git write-tree to print the current tree id
  • git commit-tree treeID -m "commit a tree" to commit this tree. After this operation, a commit object is created, and I see that it contains the author, date, etc. However, I cannot check my commits with git log , error: fatal: bad default revision 'HEAD' .

After performing the above operations, when I run git status , I see that the file is still in the index, waiting to be committed. What is the use of commit-tree and what is the difference between commit-tree and `commit '?

+5
source share
1 answer

git-commit - Write changes to the repository Saves the current contents of the index in a new commit along with a log message from the user describing the changes.

git commit "writes changes to the repository"

The git-commit diagram is shown here in SO

git-commit-tree - create a new commit object Creates a new commit object based on the provided tree object and emits a new commit object object on stdout .

This is usually not what the end user wants to run directly. Creates a new commit object based on the provided tree object and emits a new commit object id on stdout. A log message is read from standard input unless the -m or -F options are specified.

+3
source

All Articles