为什么Git使用冒号(:< branch>)来删除远程分支 [英] Why Git use the colon (:<branch>) to delete remote branch

查看:608
本文介绍了为什么Git使用冒号(:< branch>)来删除远程分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在考虑为什么Git命令使用

git push< remote> :< branch>

git push origin:featureA 删除远程服务器中的featureA分支。我很感兴趣,为什么把冒号作为删除标志。它与

git branch -d



为什么不做类似于

git branch -d --remote origin< branchname>

还是有我以前从不知道的冒号符号的深层含义?

解决方案

它本身不是的含义,而是存在的或在它之前缺少的。



refspec格式为

  +< source>:< destination> 

(可选+用于非快进)

所以,当你做一些类似于 git push origin:featureA 的东西时,你需要指定一个空的源代码,并且基本上将目标设置为空白或删除它。



PS:请注意,的refspec或没有任何意思,但并不意味着什么也不是。它使得git推送匹配分支:对于本地存在的每个分支,如果远程端已经存在相同名称的分支,则更新远程端。


I am thinking about why the Git command use

git push <remote> :<branch> like git push origin :featureA to delete featureA branch in the remote server. I am interest that why make the colon as the delete flag. It is so difference from

git branch -d <localbranch>

Why don't make something like

git branch -d --remote origin <branchname>

or there are deep meaning of colon symbol that I never know before?

解决方案

It is not the meaning of the : per se, but what is present, or rather absent before it.

The refspec format is

<+><source>:<destination>

(optional + for non-fast forward)

So when you do something like git push origin :featureA, you are specifying an empty source ref and basically making the destination "empty" or deleting it.

PS: Note that the refspec of : or nothing doesn't mean push nothing to nothing however. It makes git to push "matching" branches: for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side.

这篇关于为什么Git使用冒号(:&lt; branch&gt;)来删除远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆