更新时间:2023-11-21 16:26:58
基于@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.