是否可以配置 Git
以提醒我在启动某些 Git 命令时我的存储不为空,例如,当我切换分支时?
某些命令可以调用 githooks。
切换分支通常由 git checkout <branch>
完成。挂钩post-checkout
如果存在,则调用它,并且在运行时git checkout
可执行。复制以下脚本并粘贴到 .git/hooks/post-checkout
,然后运行 chmod 755 .git/hooks/post-checkout
。
#!/bin/bash
oldrev=$1
newrev=$2
flag=$3
# list stashes if switching branches
if [[ "${flag}" = 1 ]];then
git stash list
fi
然后,当您运行 git checkout <branch>
时,将运行git stash list
并打印存储条目(如果有(。