The git stash command is commonly used
git stash save "save message"
: Add remarks during storage for easy searchgit stash
Also want ok, but inconvenient identification when searching.git stash list
: seestash
What is stored.git stash show
To show what changes have been made, default show is the first store, if you want to show other stores, followstash@{$num}
For example, the second onegit stash show stash@{1}
.git stash show -p
To display changes to the first store, run the following command:git stash show stash@{$num} -p
, such as the second:git stash show stash@{1} -p
.git stash apply
: Applies a storage device but does not remove the storage device from the storage list. By default, the first storage device is usedstash@{0}
If you want to use another one,git stash apply stash@{$num}
, such as the second:git stash apply stash@{1}
.git stash pop
: restores the previously cached working directory, removes the corresponding stash from the cache stack, and applies the corresponding modification to the current working directory. The default is the first stash, that isstash@{0}
To apply and remove the other stash, run the following command:git stash pop stash@{$num}
For example, apply and delete the second:git stash pop stash@{1}
.git stash drop stash@{$num}
Discarded:stash@{$num}
Store, remove the store from the list.git stash clear
: Removes all cached stash files.
Note: The new file, stash directly is not stored, examples are as follows:
git status
You can see that a.txt has been modified and b.txt has been addedgit stash
And then to performgit stash list
So you can see that stash is already stored. performgit stash show
It was found that the changes showing only A.txt were stored.git status
See that B.txt is still in the workspace.
This indicates that B.stash is not stored because files that are not in Git version control cannot be stored by Git Stash.
So what do I do? I want to save this file as well, obviously, so let’s do it, okaygit add
Add it to Git version control, and thengit stash
The operation is as follows:
At this point, if you want to cut the branch, you will never get an error about uncommitted changes.
If you want to apply these stash’s, just use themgit stash apply
orgit stash pop
You can pop it up again.
Git add is only a file added to git version control, but it does not have to be stash. There is no necessary relationship between git add and Stash, but the premise of implementing git Stash is that files must be stored in Git version control.
Stash part file
The regular Git Stash version will temporarily store all files at once. Sometimes it’s more convenient to just back up some files and keep others consistent with the code base. Here’s a useful technique to use:
git add
Files that you don’t want to back up (e.g.git add file1.js, file2.js
)- call
Git stash - keep - the index
. Will only back up those that are notadd
The file. - call
git reset
Cancel the alreadyadd
Back up the files and continue your work.
Git stash — keep-index Can’t store files that are not in Git version control (files that have not been added). This can be split into two stash files.
Refer to the link: www.cnblogs.com/zndxall/arc…