如何删除使用 git stash create 创建的存储?

发布于 2024-11-02 17:42:55 字数 1157 浏览 6 评论 0原文

Git stash 似乎做了很多我想做的事情,除了编写脚本有点困难,因为如果你没有任何更改,那么 git stash; git stash pop 会做一些与你在存储库中进行更改不同的事情。

看来 git stash create 是该问题的答案,并且一切正常,除了一件事......我无法摆脱创建的存储。有什么办法可以摆脱藏匿的东西吗?

为了使其 100% 清楚我在做什么:

创建存储:

~/tmp/a(master) $ git stash create 
60629375d0eb12348f9d31933dd348ad0f038435
~/tmp/a(master) $ git st
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   b
#
~/tmp/a(master) $ git reset --hard
HEAD is now at 555d572 log message

使用存储:

~/tmp/a(master) $ git apply 60629375d0eb12348f9d31933dd348ad0f038435
fatal: can't open patch '60629375d0eb12348f9d31933dd348ad0f038435': No such file or directory
~/tmp/a(master) $ git stash apply 60629375d0eb12348f9d31933dd348ad0f038435
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   b
#

删除存储:(除了最后一点不起作用)

~/tmp/a(master) $ git stash drop !$
git stash drop 60629375d0eb12348f9d31933dd348ad0f038435
'60629375d0eb12348f9d31933dd348ad0f038435' is not a stash reference

Git stash seems to do a lot of what I want, except that it is a little hard to script, as the if you have no changes, then git stash; git stash pop will do something different than if you do have changes in your repository.

It appears that git stash create is the answer to that problem, and everything works, except for one thing… I can't get rid of the created stash. Is there any way to get rid of the stash?

To make it 100% clear what I am doing:

Create the stash:

~/tmp/a(master) $ git stash create 
60629375d0eb12348f9d31933dd348ad0f038435
~/tmp/a(master) $ git st
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   b
#
~/tmp/a(master) $ git reset --hard
HEAD is now at 555d572 log message

Use the stash:

~/tmp/a(master) $ git apply 60629375d0eb12348f9d31933dd348ad0f038435
fatal: can't open patch '60629375d0eb12348f9d31933dd348ad0f038435': No such file or directory
~/tmp/a(master) $ git stash apply 60629375d0eb12348f9d31933dd348ad0f038435
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   b
#

Delete the stash: (except that this last bit doesn't work)

~/tmp/a(master) $ git stash drop !$
git stash drop 60629375d0eb12348f9d31933dd348ad0f038435
'60629375d0eb12348f9d31933dd348ad0f038435' is not a stash reference

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

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

发布评论

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

评论(13

溺渁∝ 2024-11-09 17:42:55

git stash drop 不带任何参数 - 会删除顶部存储 - 或一个存储引用,如下所示: stash@{n} 其中 n 提名要放下哪个藏品。您无法将提交 ID 传递给 git stash drop

git stash drop            # drop top hash, stash@{0}
git stash drop stash@{n}  # drop specific stash - see git stash list

删除存储将更改堆栈中所有存储的stash@{n}名称。

我不确定您为什么认为需要删除存储,因为如果您使用stash create,则不会为您的“存储”创建存储条目,因此没有任何内容可以删除。

git stash drop takes no parameter - which drops the top stash - or a stash reference which looks like: stash@{n} which n nominates which stash to drop. You can't pass a commit id to git stash drop.

git stash drop            # drop top hash, stash@{0}
git stash drop stash@{n}  # drop specific stash - see git stash list

Dropping a stash will change the stash@{n} designations of all stashes further down the stack.

I'm not sure why you think need to drop a stash because if you are using stash create a stash entry isn't created for your "stash" so there isn't anything to drop.

烟凡古楼 2024-11-09 17:42:55

要删除使用 git stash 创建的普通存储,您需要 git stash dropgit stash drop stash@{n}。有关更多详细信息,请参阅下文。


您无需删除使用 git stash create 创建的存储。来自文档:

创建一个存储条目(这是一个常规提交对象)并返回其对象名称,而不将其存储在 ref 命名空间中的任何位置。这对于脚本很有用。这可能不是您想要使用的命令;请参阅上面的“保存”。

由于没有任何内容引用存储提交,因此它最终会被垃圾收集。


使用 git stash 或 git stash save 创建的存储将保存到 refs/stash ,并且可以使用 git stash drop 删除/代码>。与所有 Git 对象一样,实际的存储内容不会从您的计算机中删除,直到 gc 在这些对象过期后修剪它们(默认为 2 周后)。

较旧的存储保存在 refs/stash reflog 中(尝试cat .git/logs/refs/stash),并且可以使用 git stash drop stash@{n} 删除,其中 ngit stash list 显示的数字。

To delete a normal stash created with git stash , you want git stash drop or git stash drop stash@{n}. See below for more details.


You don't need to delete a stash created with git stash create. From the docs:

Create a stash entry (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace. This is intended to be useful for scripts. It is probably not the command you want to use; see "save" above.

Since nothing references the stash commit, it will get garbage collected eventually.


A stash created with git stash or git stash save is saved to refs/stash, and can be deleted with git stash drop. As with all Git objects, the actual stash contents aren't deleted from your computer until a gc prunes those objects after they expire (default is 2 weeks later).

Older stashes are saved in the refs/stash reflog (try cat .git/logs/refs/stash), and can be deleted with git stash drop stash@{n}, where n is the number shown by git stash list.

时光瘦了 2024-11-09 17:42:55

如果您 100% 确定您只有一个存储或者您想删除所有存储(制作 git 存储列表 以确保 107% 确定),您可以执行以下操作: :

git stash clear

..然后忘记它们(它会删除所有存储)。

注意:为那些最终来到这里寻找清除所有问题的方法的人(像我一样)添加了这个答案。

If you are 100% sure that you have just one stash or you want to delete all stashes (make a git stash list to be 107% sure), you can do a:

git stash clear

..and forget about them (it deletes all stashes).

Note: Added this answer for those who ended up here looking for a way to clear them all (like me).

诗化ㄋ丶相逢 2024-11-09 17:42:55

来自 git 文档: http://git-scm.com/docs/git-stash

删除[-q|--安静][]

从存储列表中删除单个存储状态。当没有给出时,它会删除最新的一个。即 stash@{0},否则必须是 stash@{} 形式的有效存储日志引用。

示例:

git stash drop stash@{5}

这将删除存储条目 5。要查看所有存储列表:

git stash list

From git doc: http://git-scm.com/docs/git-stash

drop [-q|--quiet] []

Remove a single stashed state from the stash list. When no is given, it removes the latest one. i.e. stash@{0}, otherwise must be a valid stash log reference of the form stash@{}.

example:

git stash drop stash@{5}

This would delete the stash entry 5. To see all the list of stashes:

git stash list
丿*梦醉红颜 2024-11-09 17:42:55

您应该使用

git stash save

and 不是

git stash create

因为这会创建一个存储(这是一个常规提交对象)并返回其对象名称,而不将其存储在 ref 命名空间中的任何位置。因此无法通过 stash apply 进行访问。

当您有未暂存的更改想要复制/移动到另一个分支时,请使用 git stash save "some comment"

使用 git stash apply stash@{0} (假设您已保存存储索引为 0)当您希望保存(存储)的更改反映在当前分支上时,

您始终可以使用 git stash list 来检查所有存储索引

并使用 git stash drop stash@ {0}(假设您保存的存储索引为 0 并且您想要删除它)以删除特定存储。

You should be using

git stash save

and not

git stash create

because this creates a stash (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace. Hence won't be accessible with stash apply.

Use git stash save "some comment" is used when you have unstaged changes you wanna replicate/move onto another branch

Use git stash apply stash@{0} (assuming your saved stash index is 0) when you want your saved(stashed) changes to reflect on your current branch

you can always use git stash list to check all you stash indexes

and use git stash drop stash@{0} (assuming your saved stash index is 0 and you wanna delete it) to delete a particular stash.

零度° 2024-11-09 17:42:55

处理隐藏的最好方法是,首先检查隐藏的列表

git stash list

,然后识别并确认是否有您关心的隐藏,然后继续

git stash drop

,它将一一删除隐藏(从顶部开始)

git stash drop <index>

它会删除一个隐藏在特定索引上,即5

但如果您确定该列表中没有任何内容需要,那么就去吧

git stash clear

,它会删除所有这些。

The best way to deal with stashes, first check the list of stash with

git stash list

and then identify and confirm if there's a stash of your concern then go with

git stash drop

and it will delete the stashes one by one (starts from top)

git stash drop <index>

it'll delete a stash on a specific index i.e 5

but if you're sure that nothing in that list in needed then go for

git stash clear

and it'll remove all of the them.

追我者格杀勿论 2024-11-09 17:42:55

仅删除一个存储 git stash drop

删除所有存储 git stash clear

显示您的存储 git stash show

删除特定存储 git stash drop indexnumber 例如 git stash drop 4

在这里学习 Stack 隐藏背后的概念

To delete only one stash git stash drop

Delete all stashes git stash clear

To show your stash git stash show

To remove an specific stash git stash drop indexnumber e.g git stash drop 4

Learn Stack Here the concept behind stash

深海不蓝 2024-11-09 17:42:55
git stash           // create stash,
git stash push -m "message" // create stash with msg,
git stash apply         // to apply stash,
git stash apply indexno // to apply  specific stash, 
git stash list          //list stash,
git stash drop indexno      //to delete stash,
git stash pop indexno,
git stash pop = stash drop + stash apply
git stash clear         //clear all your local stashed code
git stash           // create stash,
git stash push -m "message" // create stash with msg,
git stash apply         // to apply stash,
git stash apply indexno // to apply  specific stash, 
git stash list          //list stash,
git stash drop indexno      //to delete stash,
git stash pop indexno,
git stash pop = stash drop + stash apply
git stash clear         //clear all your local stashed code
献世佛 2024-11-09 17:42:55

对于想要从 UI 本身操作 stash 的 VS Code 用户,请使用以下方法:

  1. 确保您已经安装了 GitLens 扩展。
  2. 转到源代码管理选项卡。
  3. 检查 STASHES 部分。您将找到所有存储(与git stash list相同)
  4. 您将找到应用存储与 HEAD 比较直接按钮分别删除每个存储的存储。

输入图像描述这里

  1. 要删除特定的存储,请单击“删除存储”按钮并确认删除(删除)它。

输入图像描述这里

For VS Code users who want to operate the stash from UI itself, please use this method:

  1. Make sure you have installed GitLens extension.
  2. Go to Source Control tab.
  3. Check the STASHES section. You will find all your stashes (same like git stash list)
  4. You will find direct buttons to Apply Stash, Compare with HEAD and Delete Stash respectively for each stash.

enter image description here

  1. To drop a particular stash, click on Delete Stash button and give confirmation to delete (drop) it.

enter image description here

假情假意假温柔 2024-11-09 17:42:55

它也

git stash drop <index>

像这样工作

git stash drop 5

It also works

git stash drop <index>

like

git stash drop 5
很酷又爱笑 2024-11-09 17:42:55

git stash list

git stash drop 1

在此处输入图像描述

git stash list

git stash drop 1

enter image description here

倒数 2024-11-09 17:42:55

git stash clear 将清除完整的 stash,

cmd: git stash clear

如果你想删除带有 stash 索引的特定 stash,可以使用 drop。

cmd: git stash drop 4

(4 是存储 ID 或存储索引)

Git stash clear will clear complete stash,

cmd: git stash clear

If you want to delete a particular stash with a stash index, you can use the drop.

cmd: git stash drop 4

(4 is stash id or stash index)

Hello爱情风 2024-11-09 17:42:55

文档在这里(中文)请点击。

您可以使用

git 存储列表

git stash drop stash@{0}

在此处输入图像描述

The Document is here (in Chinese)please click.

you can use

git stash list

git stash drop stash@{0}

enter image description here

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