官术网_书友最值得收藏!

How references work

So, every time we make a commit to a branch, the reference that identifies that branch will move accordingly to always stay associated with the tip commit.

But how will Git handle this feature? Let's go back to putting the nose again in the .git folder:

[5] ~/grocery (master)
$ ll .git/
total 21
drwxr-xr-x 1 san 1049089   0 Aug 25 11:20 ./
drwxr-xr-x 1 san 1049089   0 Aug 25 11:19 ../
-rw-r--r-- 1 san 1049089  14 Aug 25 11:20 COMMIT_EDITMSG
-rw-r--r-- 1 san 1049089 208 Aug 17 13:51 config
-rw-r--r-- 1 san 1049089  73 Aug 17 11:11 description
-rw-r--r-- 1 san 1049089  23 Aug 17 11:11 HEAD
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 hooks/
-rw-r--r-- 1 san 1049089 217 Aug 25 11:20 index
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 info/
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 logs/
drwxr-xr-x 1 san 1049089   0 Aug 25 11:20 objects/
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 refs/

There's a refs folder: let's take a look inside:

[6] ~/grocery (master)
$ ll .git/refs/
total 4
drwxr-xr-x 1 san 1049089 0 Aug 18 17:15 ./
drwxr-xr-x 1 san 1049089 0 Aug 25 11:20 ../
drwxr-xr-x 1 san 1049089 0 Aug 25 11:20 heads/
drwxr-xr-x 1 san 1049089 0 Aug 17 11:11 tags/

Now go to heads:

[7] ~/grocery (master)
$ ll .git/refs/heads/
total 1
drwxr-xr-x 1 san 1049089  0 Aug 25 11:20 ./
drwxr-xr-x 1 san 1049089  0 Aug 18 17:15 ../
-rw-r--r-- 1 san 1049089 41 Aug 25 11:20 master

There's a master file inside! Let's see what's the content:

[8] ~/grocery (master)
$ cat .git/refs/heads/master
0e8b5cf1c1b44110dd36dea5ce0ae29ce22ad4b8

As you could imagine, Git manages all this articulated reference system... with a trivial text file! It contains the hash of the last commit made on the branch; in fact, if you look at the previous git log output, you can see the hash of the last commit is 0e8b5cf.

Nowadays it has been time since the first time, but I continue to be amazed by how essential and effective the internal structure of Git is.

主站蜘蛛池模板: 商洛市| 平谷区| 惠州市| 瑞丽市| 诸城市| 温宿县| 宝应县| 博兴县| 自贡市| 西林县| 江油市| 元朗区| 扬州市| 雷波县| 高清| 无棣县| 出国| 兴安县| 景谷| 桐梓县| 鹿邑县| 南漳县| 墨玉县| 长葛市| 开远市| 仁化县| 乌拉特中旗| 新竹县| 鄂托克前旗| 龙井市| 济源市| 安国市| 昭觉县| 寻乌县| 左权县| 灵武市| 江陵县| 凭祥市| 晋江市| 肃南| 淳安县|