What is the difference between using -d and -D when deleting a branch in git?

不打扰是莪最后的温柔 提交于 2019-12-25 07:53:44

问题


Can some body please help me to understand what is the difference between following two git commands?

$ git branch -d testing

and

$ git branch -D testing

When should we use -D?


回答1:


git branch -d is for deleting branches that are fully merged in its upstream branch or to HEAD if you don't have a upstream for your branch. If the branch is not fully merged it will not perform the deletion.

git branch -D deletes the branch even if it's not merged.




回答2:


In complement to the other answer: think of -D as -d --force. -d is the safe option, you probably want to teach your fingers to use this one. When -d refuses to delete the branch, make sure you know what you're doing, and then use -D.

Actually, -D sounds so much like -d --force that you can indeed use -d --force since Git 2.3.



来源:https://stackoverflow.com/questions/31185519/what-is-the-difference-between-using-d-and-d-when-deleting-a-branch-in-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!