如何判断是否不再需要 git stash?

发布于 2024-12-13 04:48:01 字数 225 浏览 0 评论 0原文

是否可以在不执行 git stash apply 的情况下判断存储是否已被应用,因此不再需要?假设我只使用一个分支。

在应用存储时,可以通过使用 pop 而不是 apply 来防止这种情况,因此每次应用存储时都将其删除。但是,我有时使用 git stash 来保存正在进行的工作的快照,而不是仅使用它从一项任务切换到另一项任务。使用 pop 会在一定程度上克服这一点。

Is it possible to tell whether a stash has already been applied, and therefore is no longer required, without doing git stash apply? Assume that I'm only using one branch.

This could be prevented by using pop rather than apply when applying a stash, and therefore get rid of the stash each time it gets applied. However, I sometimes use git stash to keep a snapshot of work in progress, rather than only using it to switch from one task to another. Using pop would defeat that somewhat.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

野心澎湃 2024-12-20 04:48:02

如果您使用 git diff stash,请确保使用 Git 2.30 (Q1 2021)。

在此之前,查看代码是否“git stash drop"(男人)< /sup> 可以安全地删除 refs/stash 已变得更加小心。

请参阅 提交 4f44c56(2020 年 10 月 24 日),作者:René Scharfe (rscharfe)
(由 Junio C Hamano -- gitster -- 合并于 提交 30f5257,2020 年 11 月 18 日)

stash:简化引用日志空值检查

报告人:Marek Mrva
签字人:René Scharfe

调用 rev-parse 来检查 drop 子命令是否删除了最后一个存储,并将其失败视为确认是脆弱的,因为该命令可能因其他原因而失败,例如因为系统内存不足。

直接检查reflog是否为空,这样更稳健。

因此,使用 git rev-parse --verify --quiet 来检查删除的存储是否是 ast 已被替换。

If you use git diff stash, make sure to use Git 2.30 (Q1 2021).

Before that, the code to see if "git stash drop"(man) can safely remove refs/stash has been made more careful.

See commit 4f44c56 (24 Oct 2020) by René Scharfe (rscharfe).
(Merged by Junio C Hamano -- gitster -- in commit 30f5257, 18 Nov 2020)

stash: simplify reflog emptiness check

Reported-by: Marek Mrva
Signed-off-by: René Scharfe

Calling rev-parse to check if the drop subcommand removed the last stash and treating its failure as confirmation is fragile, as the command can fail for other reasons, e.g. because the system is out of memory.

Directly check if the reflog is empty instead, which is more robust.

So the use of git rev-parse --verify --quiet to check if the stash dropped was the ast one has been replaced.

你的心境我的脸 2024-12-20 04:48:01

只需进行比较,您就会看到。

git diff HEAD stash@{0}

Just make a diff and you will see.

git diff HEAD stash@{0}

甜心 2024-12-20 04:48:01

您可以使用以下 shell 脚本来获取带有复选标记前缀的 git stash list(如果它们已经应用)或者不需要应用它们,因为没有区别。

git stash list | while read line; do \
  ref=${line%%:*}; \
  prefix=$(test $(git diff $ref | wc -l) = "0" && echo "✔  " || echo "   "); \
  echo "$prefix$line"; \
done

这将为您提供一个类似的列表:

✔  stash@{0}: WIP on develop: 77a1a66 send 'social.share' message via 'view-req-relay'...
   stash@{1}: WIP on bigcouch: 4bfa3af added couchdb filters...

如果您喜欢它,您可以将其添加为 git 别名,如下所示:(

git config --global --add alias.stash-list '!git stash list | while read line; do   ref=${line%%:*};   prefix=$(test $(git diff $ref | wc -l) = "0" && echo "✔  " || echo "   ");   echo "$prefix$line"; done'
git stash-list

使用 bash 和 zsh)

You can use the following shell script to get git stash list prefixed with checkmarks if they have already been applied or there is no need to apply them as there is no difference.

git stash list | while read line; do \
  ref=${line%%:*}; \
  prefix=$(test $(git diff $ref | wc -l) = "0" && echo "✔  " || echo "   "); \
  echo "$prefix$line"; \
done

This will give you a list like:

✔  stash@{0}: WIP on develop: 77a1a66 send 'social.share' message via 'view-req-relay'...
   stash@{1}: WIP on bigcouch: 4bfa3af added couchdb filters...

And if you like it you can add it as a git alias like that:

git config --global --add alias.stash-list '!git stash list | while read line; do   ref=${line%%:*};   prefix=$(test $(git diff $ref | wc -l) = "0" && echo "✔  " || echo "   ");   echo "$prefix$line"; done'
git stash-list

(tested with bash and zsh)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文