我已经发现的:
git stash list
...列出我所有的藏品。
git stash show -p stash@{0} --name-only
列出该存储中的所有文件(此处是位置 0 处的最新存储)。
现在我有一个项目,其中有数百个旧的隐藏更改,这些更改将不再需要。我知道我可以将它们全部删除:
git stash clear
...或者像这样删除单个存储(随后删除包含 87 个存储的存储):
git stash drop stash@{87}
但是我想删除隐藏的 3-107。我尝试了一个冒险的猜测:
git stash drop stash@{3-107} -- does not work
我该怎么做?
编辑:我们必须向后循环,因为删除存储会更改所有存储的索引。
git stash drop
一次不接受多个修改;
$ git stash drop stash@\{{4..1}\}
Too many revisions specified: 'stash@{4}' 'stash@{3}' 'stash@{2}' 'stash@{1}'
您可以通过 shell 中的循环来实现这一点。例如在
bash
;
$ for i in {4..1}; do
> git stash drop stash@{$i};
> done
Dropped stash@{4} (175f810a53b06da05752b5f08d0b6550ca10dc55)
Dropped stash@{3} (3526a0929dac4e9042f7abd806846b5d527b0f2a)
Dropped stash@{2} (44357bb60f406d29a5d39ea0b5586578223953ac)
Dropped stash@{1} (c97f46ecab45846cc2c6138d7ca05348293344ce)
你可以试试这个:
i=3; while [ $i -lt 104 ]; do git stash pop stash@{3}; i=$(( $i + 1 )); done
始终删除 3,因为当您删除 3 时,原来的 4 现在是 3,依此类推,因此您继续删除 stash@{3}。无论哪种方式使用时都要格外小心!
存储列表示例:
您可以使用
git stash list
命令查看您的存储列表。
stash@{0}: On main: cell click away deselet bug fix
stash@{1}: On main: stop propagation added
stash@{2}: On main: Split layout new plan button cover from drawing fixed
stash@{3}: On main: free trial changes
stash@{4}: On main: auto start free trial
stash@{5}: On main: fixed stage size with zoom
stash@{6}: On main: stage resize
stash@{7}: On main: resize half done
stash@{8}: On main: resize events removed
stash@{9}: On new-navigation-menu: project changes
stash@{10}: On main: fixed height drawing stage
stash@{11}: On main: plan image size change fail
stash@{12}: On main: plan configure model changes done
stash@{13}: On main: after merge plan sheet model
stash@{14}: On main: enter key scale model bug fixed
需要保留的藏品:从0到10
需要移除的藏品:从 11 到 14
(使用Windows终端)
git stash drop stash@{11}
我重复这个命令四次。 (您也可以使用 while 循环)
第一次:stash@{11} 已移除。
第二次:stash@{12} 已移除。
第三次:stash@{13} 已移除。
第四次:stash@{14} 已移除。
更新:
使用 for 循环(Windows 命令提示符)
for /L %n in (14,-1,11) do git stash drop stash@{%n}
完成:)
使用 bash,您可以重复命令直到失败 所以如果你想删除上面所有隐藏的物品,包括 X
while $(git stash drop stash@{X}); do :; done
当从储藏室中删除一件物品时,其他物品会向前移动,因此重复操作将删除从 X 到末尾的所有物品
对这里的答案有疑问,这对我有用:
for ((i=3; i<=23; i++)); do
git stash drop stash@{3}
done
只需使用要删除的第一个索引更新
3
,并使用最后一个索引更新 23
。