我使用以下命令删除已合并到HEAD
的本地分支。
>>> git branch | xargs git branch -d
>>> # (not -D) because I don't wanted to forced delete all the branches
但是我注意到它还删除了一个未合并到HEAD
但被推送到远程的分支。
警告并显示错误:(分支未被删除)
warning: not deleting branch 'ER-1421' that is not yet merged to 'refs/remotes/origin/ER-1421', even though it is merged to HEAD. error: The branch 'ER-1421' is not fully merged.
警告没有错误:(已从本地删除)
warning: deleting branch 'ER-2256' that has been merged to 'refs/remotes/origin/ER-2256', but not yet merged to HEAD. Deleted branch ER-2256 (was d18dafcee).
我的问题是:如何限制删除哪些删除会给任何警告或未合并到HEAD
的分支?
更新:基于@Saurav评论。我试过下面的命令
>>>git branch --merged | tr '\n' ' ' | xargs git branch -d
warning: not deleting branch 'ER-1421' that is not yet merged to
'refs/remotes/origin/ER-1421', even though it is merged to HEAD.
error: The branch 'ER-1421' is not fully merged.
If you are sure you want to delete it, run 'git branch -D ER-1421'.
error: branch '*' not found.
error: Cannot delete branch 'master' checked out at '/media/sf_workspace/personify'
warning: not deleting branch 'release-66' that is not yet merged to
'refs/remotes/origin/release-66', even though it is merged to HEAD.
error: The branch 'release-66' is not fully merged.
If you are sure you want to delete it, run 'git branch -D release-66'.
答案 0 :(得分:2)
如果你只想删除合并到HEAD的本地分支,那么我宁愿建议只选择要删除的那些完全合并到HEAD的分支。 您的命令中的一个小修改可以解决问题:
git branch --merged | xargs git branch -d
git branch --merged
仅列出完全合并的分支。然后休息,您可以使用xargs git branch -d
删除。还要确保从HEAD指向的分支运行此命令,可执行 master 分支。
希望它有所帮助!