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. In this case, git has no knowledge at all of how master and the feature branch are related, and you should definitely not reuse the branch, because git will see all of the original commits as "new" (not in master's history) and try to merge them again.Posted on June 28, 2023, 11:37 a.m. You performed a "squash merge", throwing away all the history from the feature branch, and creating a single commit with all the changes in.If you continue the branch and merge again, you might have confusion over those conflicts to avoid this, merge from master into the feature branch, so both contain the resolved code. You performed a "true merge", but resolved conflicts and pushed the result directly to master, without committing them to the feature branch. If you add more commits to the feature branch and do another true merge, git will understand which commits are new (the ones not already in master's history) and everything will be OK. The difference between the two branches is that master has that merge commit in its history but your feature branch doesn't.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |