This is the 19th day of my participation in the August Wenwen Challenge.More challenges in August
1.1 Scene Reconstruction
Suppose in our application scenario is that when using the git (which is in most cases) : the boss asked wang within 2 h change online a button to show icon, named “color 001”, wang has a look, oh my god, this simple, then slowly built a local branch of the “color 001”, change ah ah, write ah ah. Suddenly, there is an urgent bug on the line, and xiao Wang should fix it within 1H, otherwise he will not be allowed to participate in the group construction. But part of the code for “Color-changing 001” is already written, so it’s impossible to give up. Xiao Wang is worried. What should I do?
1.2 Commands
git stash
Copy the code
Stash, as the name suggests, is to store your changes under your current branch in a temporary cache. This cache is a stack for storing multiple Stash commands. Continuing the above scenario, since “Color change 001” is not finished, Xiao Wang will definitely not be able to submit the code.
First, by tapping git Stash, Git stores wang’s changes to “Color Change 001”. After storage, Wang’s workspace (or look at the IDE, did the code change back?) Restore to modify “color 001” before the state, Wang a look, and a cold sweat, do color 001 white? ! But Xiao Wang is an experienced programmer, so take your time. Then Xiao Wang knocked:
git stash list
Copy the code
We find something like the following (three times in the figure because Stash had two times before) :
Stash @{0} is the latest stash.
Oh, oh, oh, oh, oh, wang long sigh of relief, jiangshan is still there, the group has not lost.
Now, Wang can safely switch to the emergent bug branch (Git checkout -b JJBUG), and his changes are saved on the stack. After wiping the cold sweat on his head, Wang wanted to cut back to his “color-changing 001” branch and restore it to the latest modified state.
Git checkout is 001 Git Stash popCopy the code
Pop restores the storage area at the top of the stack and removes the storage.
Git stash apply stash@{XCopy the code
Apply is also the storage area at the top of the stack. Unlike git Stash pop, this command does not remove the contents from the stack, which means that it can restore the contents of the stack multiple times, suitable for multiple branches.
Wang not in a hurry to hit the git stash apply stash@{0}, ah, indeed recover, do not have to start again, Wang happy like a 200 kg fat.
When stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash stash
Git stash drop stash@{X} // Remove the corresponding stash from the record list or git stash clear // clear everything on the stackCopy the code
After wang changed it for a while, the local code was newer than the stash code, so Wang wanted to check the difference between the local code and stash code. Want to revert to the Stash version?) Here’s another name for Xiao Wang:
Git stash show stash @ {0} - p / / the -p parameter code to view the specific details of SRC/main/XXXTest/Test. The CPP | 2 + 1 file changed, 1 insertion (+), 1 deletion(-)Copy the code
At this point, I believe Xiao Wang has thoroughly mastered the use of Stash and saving the world is just around the corner!