git delete remotes:远程引用不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32147093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git delete remotes: remote refs do not exist
提问by Jqw
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 repo,它们已合并到 master 中。我可以使用以下方法一次删除这些遥控器:
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.
git branch -r --merged
列出所有合并的遥控器。grep origin
告诉命令包括原点。grep -v master
告诉命令排除主人。xargs git push origin --delete
告诉命令删除遥控器列表。
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.
然而,这些遥控器确实存在,我可以检查它们中的每一个。许多网站和人们建议我运行git fetch --prune
以清理丢失的引用。这没有任何作用,因为所有这些遥控器都存在。
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.
我想我错过了一些小东西。每次我研究这个时,似乎我都做对了,但我遇到了上述错误。
回答by Igor
You may need to prune your local "cache" of remote branches first. Try running:
您可能需要先修剪远程分支的本地“缓存”。尝试运行:
git fetch -p origin
git fetch -p origin
before deleting.
删除前。
回答by Mykola Gurov
Are those branches removed from the remote (origin)? If yes, you can simply do
这些分支是否从远程(原点)中删除?如果是,你可以简单地做
git fetch --prune origin
Otherwise they might return even after you delete them locally.
否则,即使您在本地删除它们,它们也可能会返回。
Update:Looking at your command again, it looks like you're building it incorrectly. You probably want
更新:再次查看您的命令,您似乎错误地构建了它。你可能想要
git push origin --delete myBranch-1234
but instead you are doing something like
但相反,你正在做类似的事情
git push origin --delete origin/myBranch-1234
回答by kost
Use sed
to remove 'origin/' part and change a lttile xargs
part.
使用sed
删除“原点/”部分和改变lttilexargs
一部分。
git branch -r --merged | grep origin | grep -v -e master | sed s/origin\/// | xargs -I{} git push origin --delete {}