If we look at Git documentation, we can see that this command has a parameter that is usually ignored: git checkout tree-ish - pathspec Why does one command execute two different commands? It's a little more subtle than that. If you notice the above two actions for the first time, it may seem meaningless. For example, if you switch to the Develop branch and change something in test.txt, you can use the following command to restore the file to the last modified version of the branch: git checkout - test.txt Where things get tricky is that if you take a file as a parameter in a command instead of a branch or commit, the command will discard the local changes to the file and restore it to the state of the target branch. You can also make your HEAD point to the specified COMMIT instead of the branch: git checkout f8c540805b7e16753c65619ca3d7514178353f39 For example, if you are on the main branch, you can switch to the Develop branch using the following command: git checkout develop More specifically, switch the branch to which the HEAD points. Many people use this method to switch branches locally. Git checkout is one of the things that can make Git confusing for beginners, because it's context-dependent. To understand why they're here, we need to look back at our old friend Git Checkout. To my surprise, I recently found two new commands in the list of advanced commands: That is, it works even better if you don't include git plumbing, which most people don't know about. "When I see a push, I use pull first to avoid conflict" - Anonymousįor those who have been using Git for a while, it's rare to notice what's been updated recently. And on a side note the course introduced me to the concept of atomic commits as a good practice.Posted on June 28, 2023, 11:37 a.m. There may well be a better or quicker way to do this, but this does it perfectly. "checkout - SHA" - this lets git take you back to same status as last commit and reverts all unstaged changes. "git log" - to find the last commit and copy SHA And for the record it just covered what I think I should have done: The upshot of all of this is that I need to learn git a lot better, so am just doing a course on linkedIn Learning so I don't get into this mess again. UPDATE: Thank you to all who responded to my post and apologies for lack of response, I have been on Annual Leave. Any help would be appreciated I'm panicking currently and worried I'm about to lose 5 months of work because of git when I'm trying to learn how to use it. In the past I have just had to delete the folder from my computer and clone it again from github, but there must be a way to just ignore the changes and checkout another branch. How can I just get rid of the changes, I don't need to stash them, I just need to get back to my work. The issue now is git won't let me switch to a different branch without committing and I desparately do not under any circumstances want to do that. The issue I am having is that I have made a couple of small changes just to get the site working locally to find that it is too far gone. I was trying to clean up git and use it in a better way, but the master is now so far from the branch I am working on, I will have to do it another way.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |