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

I am reading about git objects: blob, tree, commit, tag. In order to have a better understanding of how git works, I tried some low level command like write-tree and commit-tree.

  1. mkdir test; cd test –> git init
  2. I create a file and git add file. I can see a blob and tree object are generated in .git/objects
  3. git write-tree to print the current treeID
  4. git commit-tree treeID -m "commit a tree" to commit this tree. After this operation, a commit object is generated and I can see it does contain author, date, etc. However, I can’t check my commits using git log, the error is : fatal: bad default revision 'HEAD'.

After above operations, when I run git status, I see the file is still in the index waiting for commit. What is the use of commit-tree and what’s the difference between commit-tree and `commit’?

  • Git: can't commit a file even though I've resolved the conflict
  • git-svn — Why are other branches' commits mixed in with trunk commits on master?
  • Is it possible in git to just push 4 out of 5 commits?
  • “Not currently on any branch” after doing a commit
  • git commit to all branches
  • A little git trouble
  • Version control system for Excel-VBA code
  • Jenkins Git Plugin: How to build specific tag?
  • Git : List all unmerged changes in git
  • Combining merges into a single merge
  • Cassandra/Hector = How to get and compile ORM without using Maven and/or GIT from GitHub
  • what are “automerged” files in git, and how do you list them all?
  • One Solution collect form web for “What is the difference between git commit and git commit-tree”

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

    git commit “records changes to the repository”

    Diagrammatic representation of git-commit is shown here at SO

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

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

    Git Baby is a git and github fan, let's start git clone.