This is the 11th day of my participation in the August More Text Challenge. For details, see:August is more challenging

preface

Background: It’s often the case that when you’re working on one part of a project, the code is in a messy state, and for some reason you need to work on another branch. The problem is, you don’t want to and you can’t commit a half-done job, the remote branch is contaminated, and you can’t get back to the work point without committing. In this case, the best of both sides is to use the Git Stash command to temporarily store half of the code and then go back to the original branch to retrieve the stored code when the rest of the work is done!

demo

In order to demonstrate this function, I need to add some development code locally. For example, after I modify a file, I have locally developed a part of the code that is relatively messy.

At this point I received a request to switch to another branch of development. We do the stash operation and the messy code disappears

git stash save

The code that stores the current workspace changes

Git stash save "save message" git stash save "save message" git stash save "save message" git stash save "save message"Copy the code

git stash list

Viewing the Storage list

Now let’s take a look at what the stash list has committed. The previous record is already in the list, indicating that the stash is successful

Git stash list // Check stash storesCopy the code

But when we’re done developing the content and want to go back and develop the code that we’ve stored, that’s when we need to apply the stored content

git stash apply

The contents of the application store

Git stash apply stash@{$num} : git stash apply stash@{1}Copy the code

summary

After using this command, we see that the previously stored files appear in our workspace, and can happily continue to develop the previous content ~~

Other operating

git stash show

Check what file changes have been made under one stash

Git stash show // shows what changes have been made. By default, show the first stash. To show other stash, add stash@{$num}. Git stash show stash@{1} git stash show stash@{1} git stash show stash@{1Copy the code

git stash show -p

Check what changes have been made to one stash file (see the code changes).

Git stash show -p // By default, the first stash changes are displayed. To display other stash changes, run the git stash show stash@{$num} -p command. For example, run the git stash show stash@{1} -p commandCopy the code

git stash pop

Delete this storage record after the storage record is applied

Git stash pop // the difference between pop and apply is that you can delete one stash record after applying it. To apply and delete another stash record, run the git stash pop stash@{$num} command. git stash pop stash@{1}Copy the code

git stash drop

Delete storage record, do not apply

To delete the other stash stash, run the git stash drop stash@{$num} command. For example, to delete the second stash stash, run the git stash drop stash@{1} command.Copy the code

git stash clear

Delete all stash records

The summary of this chapter

This chapter introduces an operation procedure of Stash. If there are any errors, please correct them. Thank you