我可以删除当前所有的分行吗? [英] Can I delete all the local branches except the current one?
问题描述
我想删除所有在
$ git branch
但保留当前分支,一步。那可能吗?如果是这样,怎么样?
but keeping current branch, in one step. Is that possible? If so, how?
推荐答案
基于@pankijs的回答,我提出了两个git别名:
Based on @pankijs answer, I made two git aliases:
[alias]
# Delete all local branches but master and the current one, only if they are fully merged with master.
br-delete-useless = "!f(){\
git branch | grep -v "master" | grep -v ^* | xargs git branch -d;\
}; f"
# Delete all local branches but master and the current one.
br-delete-useless-force = "!f(){\
git branch | grep -v "master" | grep -v ^* | xargs git branch -D;\
}; f"
添加到〜/ .gitconfig
@torek指出:
请注意,小写
-d
不会删除非完全合并分支(请参阅文档)。使用-D
会删除这些分支,即使这会导致提交变为丢失。 非常小心地使用,因为这也删除了分支reflogs,所以通常的从意外删除中恢复的东西也不起作用。
Note that lowercase
-d
won't delete a "non fully merged" branch (see the documentation). Using-D
will delete such branches, even if this causes commits to become "lost"; use this with great care, as this deletes the branch reflogs as well, so that the usual "recover from accidental deletion" stuff does not work either.
基本上,如果你不确定你不会失去任何重要的东西,那么千万不要使用 -force
版本。因为它永远 。
Basically, never use the -force
version if you're not 300% sure you won't loose anything important. Because it's lost forever.
这篇关于我可以删除当前所有的分行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!