[英]Git stash: How to see if there are stashed changes in a branch
Let's say i'm in a branch off of master, called "my_new_stuff".假设我在 master 的一个分支中,称为“my_new_stuff”。 I have a feeling i might have stashed something in there.
我有一种感觉,我可能在那里藏了一些东西。 I'm worried that if I do
git stash pop
and i didn't stash anything it's going to shove a load of unwanted crap into my working folder.我担心如果我执行
git stash pop
并且我没有隐藏任何东西,它会将大量不需要的垃圾推入我的工作文件夹。
Can i see if there are stashed changes without unstashing them?我可以查看是否有隐藏的更改而不取消它们吗?
thanks, max谢谢,最大
The stash stores snapshots in the same way that commits do. stash 以与提交相同的方式存储快照。 You can see the contents of the stash with
你可以看到藏匿的内容
git stash list
You can reference those snapshots with the stash@{N}
notation or use the hashes shown.您可以使用
stash@{N}
表示法或使用显示的哈希值来引用这些快照。 You can use any of Git's commands that work on commits on stashes.您可以使用任何适用于存储提交的 Git 命令。 For example
例如
git diff master stash@{0}
will show you what the most recent stash would add/remove to the master
branch if you applied it there.如果您在那里应用,将向您展示最近的存储将添加/删除到
master
分支的内容。
Not quite an answer as such, but a little script I made using Peter Lundgren's answer, above, which i find very useful: when I switch branches it tells me if I have stashed changes.不完全是这样的答案,但是我使用上面的 Peter Lundgren 的答案制作了一个小脚本,我发现它非常有用:当我切换分支时,它会告诉我是否已隐藏更改。
in .git/hooks/post-checkout
#!/bin/sh
branch=$(git rev-parse --abbrev-ref HEAD)
stashes=`git stash list | grep "WIP on $branch"`
if [ "$stashes" ]
then
echo "You have the following stashes for this branch:"
echo $stashes
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.