git原理之四:index如何工作

index文件的数据变化过程

  1. 当checkout到新分支时,index文件的数据大致如图。把分支的最新commit信息拷贝到index文件中。三个工作区的文件hash相同
    • wdir表示工作区的文件hash
    • stage表示index中的文件hash
    • repo表示repository的文件hash
  1. 当工作区有改动。git status时:
  2. 当git add file时:
  3. 当git commit时:

Detached

在正常情况下,head 指针永远指向branch, 然后branch指向最新的commit。

但是可以通过git checkout把head指向任意的commit id。而不是指向branch。此时就叫做head detached。

如果此时我们在head指向的commit基础上提交新的commit, commit会成功,且形成一个链,但是不属于任何branch。

不属于任何branch的commit, 在一段时间之后会被垃圾回收,也就是会丢失。因此当处于head detached状态时,为当前的head创建一个branch是正确的做法

Ref

  1. https://medium.com/hackernoon/understanding-git-index-4821a0765cf
  2. https://medium.com/hackernoon/https-medium-com-zspajich-understanding-git-data-model-95eb16cc99f5
  3. https://medium.com/hackernoon/understanding-git-branching-2662f5882f9
  4. https://hackernoon.com/reset-101-ba05d9e3f2c7
  5. https://kolosek.com/git-branches/
  6. https://git-scm.com/book/en/v2
  7. https://backlog.com/git-tutorial/git-workflow/
  8. https://medium.com/@shalithasuranga/how-does-git-work-internally-7c36dcb1f2cf

索引

~~~异次元传送门



《 “git原理之四:index如何工作” 》 有 3 条评论

  1. Leukemia can be associated with the use of cyclophosphamide, doxorubicin, and epirubicin buy generic lasix

  2. Meerwein Ponndorf reduction gives the chromanol cialis with priligy

  3. buy priligy 30 mg x 10 pill However, it could potentially raise the risk of breast cancer recurrence, especially in patients with hormone receptor positive tumors

回复 agodelo 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注

About Me

一位程序员,会弹吉他,喜欢读诗。
有一颗感恩的心,一位美丽的妻子,两个可爱的女儿
mail: geraldlee0825@gmail.com
github: https://github.com/lisuxiaoqi
medium: https://medium.com/@geraldlee0825