问题描述
总之;
- 如何删除远程多个合并的远程?
更多背景信息
我有一个git仓库,有数十个已被合并到master中的远程仓库。我可以通过以下方式一次删除这些遥控器:
git push --delete origin myBranch-1234
然而,对于所有遥控器来说,这是一个缓慢且乏味的过程。所以我试着这个命令:
git branch -r --merged | grep origin | grep -v master | xargs git push origin - 删除
git branch -r --merged
列出所有合并的遥控器。
grep origin
告诉命令包含原点。
grep -v master
告诉命令排除master。
xargs git push origin --delete
告诉命令删除遥控器列表。
所有这些,我希望能够收集所有合并的遥控器并将其删除。
错误:无法删除'origin / myBranch-1234':远程参考不存在
错误:无法删除'origin / myBranch-1235':远程参考不存在
错误:无法删除'origin / myBranch-1236':远程引用不存在
错误:无法删除'origin / myBranch-1237':远程引用不存在
... etc
然而这些遥控器确实存在,而我可以检查他们每个人。许多网站和人员建议我运行 git fetch --prune
来清除缺少的引用。
所以我问你,亲爱的堆栈交换;
- 为什么我可以删除一个远程,但不是很多?
- 我的命令是否正确?
我想我错过了一些小事。每次我研究这一点,似乎我正确地做了这件事,但我得到了上述错误。
您可能需要首先修剪远程分支的本地缓存。尝试运行:
git fetch -p origin
在删除之前。
In short;
- How can I delete remote multiple merged remotes?
More background;
I have a git repo with tens of remotes which have been merged into master. I can delete these remotes one at a time by using:
git push --delete origin myBranch-1234
However this is a slow and tedious process for all remotes. So I'm trying this command:
git branch -r --merged | grep origin | grep -v master | xargs git push origin --delete
git branch -r --merged
lists all merged remotes.grep origin
tells the command to include origin.grep -v master
tells the command to exclude master.xargs git push origin --delete
tells the command to delete the list of remotes.
All together, I expect this to gather all merged remotes and delete them.
When I run the above command, I receive the following for every merged remote;
error: unable to delete 'origin/myBranch-1234': remote ref does not exist
error: unable to delete 'origin/myBranch-1235': remote ref does not exist
error: unable to delete 'origin/myBranch-1236': remote ref does not exist
error: unable to delete 'origin/myBranch-1237': remote ref does not exist
... etc
However these remotes do exist and I can checkout each of them. Many sites and people recommend that I run git fetch --prune
to clean up missing references. This does nothing because all of these remotes exist.
So I ask you, dear stack exchange;
- Why can I delete one remote, but not many?
- Is my command correct?
I think I'm missing something small. Every time I research this, it seems like I'm doing this correctly, but I'm getting the above errors.
You may need to prune your local "cache" of remote branches first. Try running:
git fetch -p origin
before deleting.
这篇关于git删除遥控器:遥控器不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!