Difference between HEAD / Working Tree / Index in Git

来源:互联网 发布:mdf数据库恢复 编辑:程序博客网 时间:2024/06/05 06:36

转载至http://stackoverflow.com/questions/3689838/difference-between-head-working-tree-index-in-git

A few other good references on those topics:

  • My Git Workflow

alt text

I use the index as a checkpoint.
When I’m about to make a change that might go awry — when I want to explore some direction that I’m not sure if I can follow through on or even whether it’s a good idea, such as a conceptually demanding refactoring or changing a representation type — I checkpoint my work into the index.
If this is the first change I’ve made since my last commit, then I can use the local repository as a checkpoint, but often I’ve got one conceptual change that I’m implementing as a set of little steps.
I want to checkpoint after each step, but save the commit until I’ve gotten back to working, tested code.

  • Why Git is better than X

alt text

  • Git Is Your Friend not a Foe Vol. 3: Refs and Index

They are basically named references for Git commits. There are two major types of refs: tags and heads.

  • Tags are fixed references that mark a specific point in history, for example v2.6.29.
  • On the contrary, heads are always moved to reflect the current position of project development.

alt text

Now we know what is happening in the project.
But to know what is happening right here, right now there is a special reference called HEAD. It serves two major purposes:

  • it tells Git which commit to take files from when you checkout, and
  • it tells Git where to put new commits when you commit.

When you run git checkout ref it points HEAD to the ref you’ve designated and extracts files from it. When you run git commit it creates a new commit object, which becomes a child of current HEAD. Normally HEAD points to one of the heads, so everything works out just fine.

alt text

0 0
原创粉丝点击