Git stash

949    Asked by RadhikaPatel in Devops , Asked on Nov 3, 2019
Answered by Radhika Patel

Git stash is used:

when you want to preserve the changes but aren’t ready enough to add it to the history with proper commit

when you are not sure about the code but quickly want to check out to other branch and work

when you want to apply some local config files and other resources (which are just applicable to you so you don’t add them to git)

Stashed changes are stored (as 40 character hash inside .git/refs

cat .git/refs/stash

You can view the stash. It’s stored as a stack, latest stashes being at the top. You can either pop off the stash (git stash pop stash@{n}) which applies and removes the stash entry. Or if it’s something you would want again you can just apply using: git stash apply stash@{n}

You can just see the stash using:

git stash show stash@{n}

git stash show -p stash@{n}

Example:

git stash list

stash@{0}: On release_12.37: projectCompile

stash@{1}: On release_12.37: localConfigSqlLogs



Your Answer

Interviews

Parent Categories