简体   繁体   中英

How git tracks commits in branches?

I'm new to git and i've been exploring it since last month. I understand it's very powerful as compared to other version control system. Yesterday i learnt that git branches are just files that store the head(SHA1) of the commit as listed in .git/refs/heads/ directory. my question is : How does git track the whole branch by just one commit(SHA1)? When i do :

 `git show {SHA1}` 

it shows me that commit diff only. how does a commit knows which commit(s) is/are it's parents? When i do

`git rev-parse HEAD^1`

how does it shows me the commit which was before it. Initially i use to think a branch stores all of the commits involved in some specific order but now this fact has confused me totally.

Commits are stored as a Directed Acyclic Graph . If you have no merge commits in your history, then going back from a single branch head is equivalent to a linked list.

You can see the full contents of a commit by using:

git cat-file commit HEAD

The tree line refers to the contents of that commit (eg as seen by git ls-files ). Note that this is different than some other VCSes, which store deltas rather than trees.

The parent line(s), if any, are links to the previous commits.


Generally, if you want this kind of low-level information, you should use commands listed under LOW-LEVEL COMMANDS (PLUMBING) in git 's man page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM