What about git stash and git unstash

foreword

In daily development, we unintentionally develop some codes on the master branch. Since most companies have permission to submit and merge the master branch code, if the code is written on the master branch but cannot be pushed to the remote warehouse, at this time What should I do, should I copy all the local code, cut to a new branch, and then paste the code? This can definitely be achieved, but if the modified code is more and scattered, this method of Ctrl+C plus Ctrl+V will definitely not work.

git stash和git unstash

Git must have considered the above scenario, let’s take a look at the git stash and git unstash commands together

git stash 
git stash save “save message”  //保存备注

git stash temporarily stores the files in the current workspace, each time git stash will generate a stash@{no}, that is, put it in a list, no is the number of the list, select the corresponding stash@{no} when restoring

git stash list

git stash list to view all temporary stash lists

git stash show stash@{no}

git stash show stash@{no} View the contents of the specified temporary file

git stash pop

The git stash pop command restores the previously cached working directory, deletes the corresponding stash in the cache stack, and applies the corresponding modification to the current working directory. The default is the first stash, that is, stash@{0}. If you want to apply and Delete other stash, command: git stash pop stash@{$num}, such as apply and delete the second one: git stash pop stash@{1}

git stash apply stash@{no}

git stash apply applies a storage, but does not delete the storage from the storage list. By default, the first storage is used, namely stash@{0}. If you want to use other ones, git stash apply stash@{$num}, for example Second: git stash apply stash@{1}

git stash drop stash@{no}

git stash drop drops stash@{num} stash, removes this stash from the list

git stash clear 

git stash clear deletes all cached stash

Guess you like

Origin blog.csdn.net/qq_28165595/article/details/130179673