What is a git commit object? How is it read?

Devops Devops in Devops . 2 years ago

  0   0   0   0   0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

When a project repository is initialized to be a git repository, git stores all its metadata in a hidden folder “.git” under the project root directory.
Git repository is a collection of objects. 

Git has 4 types of objects – blobs, trees, tags, and commits.

Every commit creates a new commit object with a unique SHA-1 hash_id.
Each commit object has a pointer reference to the tree object, its parent object, author, COMMITTER and the commit message.

Diagram: Single Commit object

To see the commit log message along with the textual diff of the code, run:
git show <commit_id>

Divya1@Divya:initialRepo [master] $git show f9354cb commit f9354cb08d91e80cabafd5b54d466b6055eb2927 Author: divya bhushan <divya_bhushan@hotmail.com> Date:   MON Feb 11 23:39:24 2019 +0100     Add database logs. diff --git a/logs/db.log b/logs/db.log new file mode 100644 INDEX 0000000..f8854b0 --- /dev/null +++ b/logs/db.log -0,0 +1 +database logs

To read a commit object git has ‘git cat-file’ utility.

Divya1@Divya:initialRepo [master] $git cat-file -p f9354cb tree 2a85825b8d20918350cc316513edd9cc289f8349 parent 30760c59d661e129329acfba7e20c899d0d7d199 author divya bhushan <divya_bhushan@hotmail.com> 1549924764 +0100 committer divya bhushan <divya_bhushan@hotmail.com> 1549924764 +0100  Add database logs.

A tree object is LIKE an OS directory that stores references to other directories and FILES (blob type).

Divya1@Divya:initialRepo [master] $git cat-file -p 2a85825b8d20918350cc316513edd9cc289f8349 100755 blob 054acd444517ad5a0c1e46d8eff925e061edf46c README.md 040000 tree dfe42cbaf87e6a56b51dab97fc51ecedfc969f39 code 100644 blob e08d4579f39808f3e2830b5da8ac155f87c0621c dockerfile 040000 tree 014e65a65532dc16a6d50e0d153c222a12df4742   logs

Posted on 31 May 2022, this text provides information on Devops related to Devops in Devops. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Tuteehub forum answer Answers

Post Answer

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.