![]() ![]() ![]() This file contains the hash of the last commit on that branch, meaning the tip of the branch. When a branch, like main is checked out it contains:įor each branch Git also keeps a file in the refs/heads directory, for instance the file refs/heads/main for the main branch will be there. ![]() git/HEAD which keeps Git informed about the branch that should be advanced in the advent of new commits. ![]() That doesn't matter right here because of the constraints I placed on what can be in $var, but in more complicated cases, it does. :-) )ĢNote that the expansion from $var to whatever $var was set-to is done by the shell (e.g., by bash), not by Git. Eventually you'll find out what's at the center of the onion. The verb peel here is meant to remind one of peeling an onion: if you find another layer of onion, peel again. (This "peeling" process repeats if needed, because the target of an annotated tag can be another annotated tag. This is all designed to be exactly what's needed if you are writing your own fancy script to do something useful with commits. If it doesn't find a commit-if it finds a tree or blob instead- git rev-parse will spit out an error message and fail the parse. If the immediate object has type annotated-tag, Git will "peel off" (follow to its destination) the tag to find its commit. That is, suppose we have some shell variable $var set to some non-empty but sensible word: it might be set to master, or maybe master^ suffix trick to tell Git: make sure the final object has type commit. It will do this whenever necessary (provided the first part allows the checkout operation).įor git checkout, it will do the second operation based on the branch name or commit specifier argument you give it. It will do this whenever it is allowed and necessary.Īnother is to change the branch name recorded in HEAD, or set up HEAD as a detached HEAD at the specified commit. One of git checkout's jobs is to populate the index and work-tree based on the target commit. git switch which can switch branches, or detach one if requested, in order for all new commits to be added to the tip of this branch.īesides VonC's answer (and the upcoming change in Git 2.23), it's worth noting a few more items.īecause git checkout does multiple different things, it's inherently confusing.git restore which updates the working tree (and possibly the index).That is why Git 2.23 (Q3 2019) will split checkout into: In my ideal world, these two modes of operation would have different verbs, and neither of them would be “ checkout”. This is seen in the usages: git checkout - (update from the index) and git checkout - (where is typically a commit). To replace a file or multiple files in the working copy and the index with their content from a particular commit or the index.HEAD will point to the ref name) or if it otherwise resolves to a commit will detach HEAD and point it directly to the commit’s object name. If is genuinely a local branch, this will switch to that branch (i.e. To switch HEAD to point to a new branch or commit, in the usage git checkout.In fact, it has two largely distinct modes of operation: However, in git, “ git checkout” is used for something completely distinct. The closest command in Git is “ git clone”. In CVS and Subversion “checkout” creates a new local copy of the source code that is linked to that repository. He also wrote in May 2012: " The most confusing git terminology": Mark Longair documented that confusion in " Why is the git command to switch branches named “ git checkout”?" While a git checkout does a switch: it prepares for working on, switch to it by updating the index and the files in the working tree, and by pointing HEAD at the branch. A git checkout, Prepare to work on top of, by detaching HEAD at it (see " DETACHED HEAD" section), and updating the index and the files in the working tree. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |