In the actual development work, you may encounter this situation:
When you’re in dev_ branch_ 1 branch work, suddenly interrupted, said that the master branch has an emergency bug, you need to fix it immediately
At this point, dev_ branch_ There are more than 20 uncommitted documents on branch 1. What should we do?
No, it’s unprofessional. In Git’s development mode, every commit should correspond to a feature / bug submission. When a commit contains multiple functions, it will increase your partner’s workload for later maintenance, such as others tracking bugs and locating code
So, in the case of the above situation, what should be the correct git operation?
The answer is stash operation
What is git stash?
All uncommitted modifications (workspace and buffer) can be saved to the stack for subsequent recovery of the current working directory
In the above scenario, how to use git stash?
In fact, in the above scenario, we need to do four steps
- Save unfinished work temporarily, but not commit it
- Switch to the master branch to solve the bug
- Switch back to your own dev branch
- Take the unfinished work in 1 back to the dev branch
So, which commands should be used to complete the four steps?
The answer is:
//Put the unfinished work on hold git stash //Switch to the master branch to solve the bug git checkout -b master //Switch back to your own dev branch git checkout -b dev //Take the unfinished work in 1 back to the dev branch git stash po
Next, please see the corresponding diagram of these four steps
The above is the operation of GIT stash