The git stash command is commonly used

  1. git stash save "save message": Add remarks during storage for easy searchgit stashAlso want ok, but inconvenient identification when searching.
  2. git stash list: seestashWhat is stored.
  3. git stash showTo 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}.
  4. git stash show -pTo 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.
  5. 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}.
  6. 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}.
  7. git stash drop stash@{$num}Discarded:stash@{$num}Store, remove the store from the list.
  8. git stash clear: Removes all cached stash files.

Note: The new file, stash directly is not stored, examples are as follows:

git statusYou can see that a.txt has been modified and b.txt has been addedgit stashAnd then to performgit stash listSo you can see that stash is already stored. performgit stash showIt was found that the changes showing only A.txt were stored.git statusSee 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 addAdd it to Git version control, and thengit stashThe 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 applyorgit stash popYou 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:

  1. git addFiles that you don’t want to back up (e.g.git add file1.js, file2.js)
  2. callGit stash - keep - the index. Will only back up those that are notaddThe file.
  3. callgit resetCancel the alreadyaddBack 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…