![]() ![]() If we look at the git documentation, we can see that the command has an extra argument that is usually omitted: If you first look at these two behaviors you might think that it doesn't make any sense, why have one command do 2 different actions? Well, things are a little more subtle than that. Git checkout - test.txt A method to the madness Where things get tricky is that if you provide a file as an argument instead of a branch or commit, it will discard your local changes to that file and restore it to the branch state.įor example, if you checked out the develop branch and you made some changes to the test.txt file, then you can restore the file as it is in the latest commit of your branch with: You can also make your HEAD pointer reference a specific commit instead of a branch(reaching the so-called detached HEAD state): For example, you can switch to the develop branch if you are on the main branch: ![]() More exactly, to switch the branch to which HEAD points. The way most people use it is to switch the active branch in their local repo. And that is because its effect is context-dependent. Git checkout is one of the many reasons why newcomers find git confusing. To understand why they came to be, let's first visit our old friend git checkout. To my surprise, I recently found out about 2 new additions to the list of high-level commands: ![]() That is if you exclude the plumbing commands which probably most of us don't know by heart and most likely that's for the better. "When I see a door with a push sign, I pull first to avoid conflicts" - anonymousįor those that work with git for some time, it is not often that you get to discover new things about it. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |