如何删除使用 git stash create 创建的存储?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
git stash drop
不带任何参数 - 会删除顶部存储 - 或一个存储引用,如下所示:stash@{n}
其中n
提名要放下哪个藏品。您无法将提交 ID 传递给git stash drop
。删除存储将更改堆栈中所有存储的
stash@{n}
名称。我不确定您为什么认为需要删除存储,因为如果您使用
stash create
,则不会为您的“存储”创建存储条目,因此没有任何内容可以删除。git stash drop
takes no parameter - which drops the top stash - or a stash reference which looks like:stash@{n}
whichn
nominates which stash to drop. You can't pass a commit id togit stash drop
.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.要删除使用
git stash
创建的普通存储,您需要git stash drop
或git stash drop stash@{n}
。有关更多详细信息,请参阅下文。您无需删除使用
git stash create
创建的存储。来自文档:由于没有任何内容引用存储提交,因此它最终会被垃圾收集。
使用 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}
删除,其中n
是git stash list
显示的数字。To delete a normal stash created with
git stash
, you wantgit stash drop
orgit 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:Since nothing references the stash commit, it will get garbage collected eventually.
A stash created with
git stash
orgit stash save
is saved torefs/stash
, and can be deleted withgit stash drop
. As with all Git objects, the actual stash contents aren't deleted from your computer until agc
prunes those objects after they expire (default is 2 weeks later).Older stashes are saved in the
refs/stash
reflog (trycat .git/logs/refs/stash
), and can be deleted withgit stash drop stash@{n}
, wheren
is the number shown bygit stash list
.如果您 100% 确定您只有一个存储或者您想删除所有存储(制作
git 存储列表
以确保 107% 确定),您可以执行以下操作: :..然后忘记它们(它会删除所有存储)。
注意:为那些最终来到这里寻找清除所有问题的方法的人(像我一样)添加了这个答案。
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:..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).
来自 git 文档: http://git-scm.com/docs/git-stash
从存储列表中删除单个存储状态。当没有给出时,它会删除最新的一个。即
stash@{0}
,否则必须是 stash@{} 形式的有效存储日志引用。示例:
这将删除存储条目 5。要查看所有存储列表:
From git doc: http://git-scm.com/docs/git-stash
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:
This would delete the stash entry 5. To see all the list of stashes:
您应该使用
and 不是
因为这会创建一个存储(这是一个常规提交对象)并返回其对象名称,而不将其存储在 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
and not
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 branchUse
git stash apply stash@{0}
(assuming your saved stash index is 0) when you want your saved(stashed) changes to reflect on your current branchyou can always use
git stash list
to check all you stash indexesand use
git stash drop stash@{0}
(assuming your saved stash index is 0 and you wanna delete it) to delete a particular stash.处理隐藏的最好方法是,首先检查隐藏的列表
,然后识别并确认是否有您关心的隐藏,然后继续
,它将一一删除隐藏(从顶部开始)
它会删除一个隐藏在特定索引上,即5,
但如果您确定该列表中没有任何内容需要,那么就去吧
,它会删除所有这些。
The best way to deal with stashes, first check the list of stash with
and then identify and confirm if there's a stash of your concern then go with
and it will delete the stashes one by one (starts from top)
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
and it'll remove all of the them.
仅删除一个存储
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.ggit stash drop 4
Learn Stack Here the concept behind stash
对于想要从 UI 本身操作 stash 的 VS Code 用户,请使用以下方法:
git stash list
相同)For VS Code users who want to operate the stash from UI itself, please use this method:
git stash list
)它也
像这样工作
It also works
like
git stash list
git stash drop 1
git stash list
git stash drop 1
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)
文档在这里(中文)请点击。
您可以使用
The Document is here (in Chinese)please click.
you can use