Hacker News new | past | comments | ask | show | jobs | submit login

That is not a good description of what checkout does. :)

That is one of the things checkout can do, if you pass it a commit hash as the only argument. If you pass it a branch name, it does something quite different (a branch does not represent a specific point). If you pass it the path of a file, it does something quite different again. And depending on what extra flags you pass it, it'll do different things again, including creating a new branch, which is entirely different again.




> That is one of the things checkout can do, if you pass it a commit hash as the only argument.

No, that's all that git checkout does: check out prior commits.

Passing a branch name actually points to the branch HEAD, which marks a specific commit made in a specific point in time.

Passing a tag also does the same thing: check out a specific commit.

Passing a file path does the exact same thing: check out the contents of a specific file as saved in a specific commit represented by the branch HEAD. It's the exact same thing as git checkout <branch> or git checkout <tag>, except it does not update the whole working copy.

> And depending on what extra flags you pass it, it'll do different things again, including creating a new branch, which is entirely different again.

That's false as well. Running git checkout -b may be syntactic sugar for git branch && git checkout but what you are asking git to do, again, is to checkout a specific commit that represents the state of the repository at a specific point in time. That's it.

All git does is enable users to navigate and edit a graph of commits. It takes a poor mental model of git and a poor understanding of what git does to fail to understand that all git checkout does is checkout a commit done somewhere in the past.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: