brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git stash show -p shows what is inside a stash before you apply it

Git
~/tips/tip-git-stash-show-patch

git stash show -p stash@{1}

Prints the full diff of a stash, so you know what you are about to bring back.

After a few days, git stash list is a pile of near identical WIP lines. Before I apply one, I want to see what’s in it.

git stash show -p stash@{1}

Without options, git stash show gives only a diffstat: which files changed and how many lines. -p shows the full patch, like git diff. Leave out the stash name and it shows the newest one, stash@{0}.

Other diff options work too. I like --stat, and git stash list takes it too, so you can scan all stashes at once:

git stash list --stat

That shows the diffstat under each entry, which is often enough to recognise the one you want.

If you only need one file out of a stash, you don’t have to apply the whole thing. git restore --source=stash@{1} -- path/to/file copies just that file into your working tree.

A catch with untracked files: if you stashed with -u, the new files live in a separate part of the stash and plain git stash show -p leaves them out. Add --include-untracked to see them, or you might think the stash is missing work that’s actually there.

Further reading: git-stash documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link