如果我有任何文件更改,我可以阻止git stash pop / apply吗?

问题描述 投票:-2回答:1

我打破了自己的规则,即在我的git stash堆栈中有多个项目,并且我qazxswwied其中两个而不是一个。

这意味着我有两组更改,没有冲突,现在是无法更改的,我无法轻易分开1。

那么有没有办法让stash pop / apply interactive,并且在继续之前检查我没有跟踪或未跟踪的更改?


1如果发生冲突,我可以像git stash pop一样使用重置

git git-stash
1个回答
2
投票

您可以为git stash pop创建别名,或者应用该检查来检查HEAD的差异。

Actually undo git stash pop

使用qazxsw poi进行前缀,并将它们包装在函数调用qazxsw poi中,允许将参数传递给[alias] pop = !"f() { { git diff-index --quiet HEAD && git stash pop \"$@\"; } || echo \"Can't pop, you have local changes\"; }; f " apply = !"f() { { git diff-index --quiet HEAD && git stash apply \"$@\"; } || echo "Can't apply, you have local changes"; }; f" !

命令f() { ... }; f "将返回0或1,具体取决于是否存在局部更改,然后git stash popgit stash apply快捷方式将继续使用git stash pop / apply,或输出错误消息。

将第一部分(使用git diff-index --quiet HEAD快捷方式)包含在大括号中(因此它是&&)可以防止在弹出或应用失败时使用||快捷方式触发的错误消息。

然后你可以使用&&安全地运行{ a && b; } || c而不会干扰其他变化。

© www.soinside.com 2019 - 2024. All rights reserved.