index文件的数据变化过程
- 当checkout到新分支时,index文件的数据大致如图。把分支的最新commit信息拷贝到index文件中。三个工作区的文件hash相同
- wdir表示工作区的文件hash
- stage表示index中的文件hash
- repo表示repository的文件hash
- 当工作区有改动。git status时:
- 当git add file时:
- 当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
- https://medium.com/hackernoon/understanding-git-index-4821a0765cf
- https://medium.com/hackernoon/https-medium-com-zspajich-understanding-git-data-model-95eb16cc99f5
- https://medium.com/hackernoon/understanding-git-branching-2662f5882f9
- https://hackernoon.com/reset-101-ba05d9e3f2c7
- https://kolosek.com/git-branches/
- https://git-scm.com/book/en/v2
- https://backlog.com/git-tutorial/git-workflow/
- https://medium.com/@shalithasuranga/how-does-git-work-internally-7c36dcb1f2cf
回复 agodelo 取消回复