Some tips on using Git Stash

git stash save

Similar to Git Stash, but with some parameters.

git stash with message

Git Stash Save "Your Stash message".Copy the code

Stash carries some messgage information, which can easily identify what changes are made in stash content.

stashing untracked files

By default, git Stash caches the following files:

  • Passage Changes Added to staged storage
  • Unstaged changes tracked by Git that were not added to staging

The file is not cached:

  • New untracked files in the working directory
  • Ignored Files

Stash Files that are not tracked

git stash save -u
or
git stash save --include-untracked
Copy the code

git stash list

When you use git Stash or Git Stash Save, Git actually creates a Git Commit with a name that is stored in the Repo. You can view some of stash’s records with the following command.

git stash list
Copy the code

You can see the stash record, with the latest stash at the top. You can add some stash messages to stash by using git Stash save “Your Stash message”.

git stash apply

Apply the most recent stash list to the repO. You can also carry the Stash ID when applying

git stash apply stash@{1}
Copy the code

git stash pop

This is very similar to git Stash apply, but is removed from the Stash list after apply.

You can also specify stash ID.

git stash pop stash@{1}
Copy the code

git stash show

This command displays the Stash Diff summary. By default, only the most recent stash is displayed.

You can use this if you want to see the full difference

git stash show -p
Copy the code

You can also specify stash ID.

git stash show stash@{1}
Copy the code

git stash branch

Create a new branch with the most recent Stash and then delete it. You can specify Stash ID.

git stash branch <name> stash@{1}
Copy the code

git stash clear

Remove all stash in the repo.

git stash drop

Delete the most recent stash. You can also specify Stash ID.

git stash drop stash@{1}
Copy the code

Useful tricks you might not know about Git stash