0. Introduction
- The picture shown in the tutorial is a github warehouse image, please visit the original address of a friend with slow speed
- Take a look at the personal tech Station when you're free.
In the actual project development, always encounter the code to write half (unable to hit commit
), to open a new branch to fix bugs or increase the functionality of the situation. If you do not, the unmodified code is brought into a new branch that is created temporarily, and the code that is not finished is mixed with the code to be repaired, absolutely bitter. And Git stash
is used to deal with this situation.
1. Initial knowledge
git stash
stash
In English the meaning is: hide. In the process of GIT code management, it is also hiding the unfinished code, preventing it from interfering with the work of others or the new branch.
About git stash
, common commands are as follows:
Command |
function |
git stash |
Hide the current job site, at this point, git status the result isclean |
git stash list |
View all hidden, the string preceding the colon of each line is the one that identifies this hiddenid |
git stash apply <id> |
To re-display the hidden identity as ID |
git stash drop <id> |
git apply After you hide, you need to manually delete the records in the list |
2. Application and actual combat
Suppose: Just as I was writing a document on the master branch ( not completed, not submitted ), my colleague found that hello.py
the script was problematic and the emergency report was repaired.
Receiving reports, subconsciously, is to open a debug branch to handle the bug. However, the current document is not completed, nature can not submit, and can not be submitted to the newly created Debug branch (this is determined, I can not:)). Currently, the status is as follows:
In order to achieve the goal, it is divided into the following steps:
- Hide changes:
git stash
:
- To create a new branch:
git branch debug
- Fix the bug on the
debug
branch and add the modifications to log:
- Go back to the
master
branch, merge debug
The branch's modifications, and delete the debug
branch:
- Re-display the hidden and
stash
remove it from the stash list
list:
- Then you can happily continue to do their own things!
3. Expand Reading
In the actual production process, will inevitably encounter a number of stash situation. At this point, their ID by default is: stash{0}
, stash{1}
, stash{2}
...
When we restore a stash and remove it from the Stash list, the ID of the stash record below it automatically becomes smaller to ensure that the ID is a contiguous natural sequence of 0 to N. therefore, when a stash is removed from the stash list, some stash IDs change . Here is a pit.