Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

commit

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'?

like image 379
hakunami Avatar asked Apr 14 '15 09:04

hakunami


People also ask

What is the difference between a tree and commit?

tree — A tree object contains references to other blobs or subtrees. commit — A commit object contains the reference to another tree object and some other information(author, committer etc.) tag — A tag or a tag object is just another reference to a commit object and just makes for easier referencing.

What is commit tree in git?

git-commit-tree is a low level command which commits a single tree object but does not perform any of the follow-up reference and Head work that git-commit does.

What is the difference between git commit and git commit?

– Git commits are local meaning they are recorded only on the machine on which the commits actually occur. The “git commit” command is used to tell Git to save your changes to the local repository and you have to specifically tell Git which changes you wish to include in a commit before using the “git commit” command.

What is the difference between git commit and git push?

Commit - committing is the process which records changes in the repository. Think of it as a snapshot of the current status of the project. Commits are done locally. Push - pushing sends the recent commit history from your local repository up to GitHub.


1 Answers

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.

like image 178
Tharif Avatar answered Oct 05 '22 02:10

Tharif