我想删除在...的输出中列出的所有分支。
$ git branch
...但是一步一步地保持当前分支。那可能吗?如果是这样,怎么办?
基于@pankijs答案,我做了两个git别名:
[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
会删除此类分支,即使这会导致提交“丢失”;请谨慎使用,因为这也会删除分支引用日志,因此通常的“从意外删除中恢复”的方法也不起作用。
基本上,-force
如果您不确定300%不会丢失任何重要内容,请不要使用该版本。因为它永远消失了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句