4 ms·
And even if the concepts are not new, the post seems very misleading. Something describing itself as teaching "the hard way" should certainly avoid fuzzy statem
by maxdamantus 9y ago
And even if the concepts are not new, the post seems very misleading. Something describing itself as teaching "the hard way" should certainly avoid fuzzy statements such as the following:
> HEAD is a special reference that always points to where the git repository is.
This kind of makes sense if you think about it a certain way (it generally points to something (possibly indirectly) that the index/working tree is based off), but off-hand, "where the git repository is" sounds like it means the location of the repository within the filesystem or something.
> If you checked out a branch, it’s pointed to the last commit in that branch. If you checked out a specific commit, it’s pointed to that commit.
This is inaccurate. When you check out a branch, HEAD points to the ref for the branch, which in turn usually points to a commit.
> Every time you commit, the HEAD reference/pointer is moved from the old to the new commit.
This is wrong unless you're in a "detached HEAD" state. `git commit` updates a ref that does not point to another ref. If you're in a "detached HEAD" state, that means HEAD is updated (since HEAD is pointing directly to a commit). If you've checked out a branch, that branch's ref will usually be updated (since HEAD is pointing to a ref which points directly to a commit).
In my opinion, git is best described in terms of what is ACTUALLY happening in terms of modifications to the refs database (essentially a `Map FilePath (Either FilePath ObjectId)`), rather than trying to come up with metaphors for what it means to perform certain actions. When I say that "HEAD points to the ref for the branch", that is demonstrably exactly what happens:
> $ cat .git/HEAD
> ref: refs/heads/master
> $ git checkout -b other-branch
> $ cat .git/HEAD
> ref: refs/heads/other-branch
> $ git checkout --detach
> ffd914475c61c18c684ccb0024ca141c54255e28
Understanding this basic concept should make most of the concepts explored in sections 1) and 2) of the article self-explanatory.