【问题标题】:How would I git remote prune just a specific remote branch?我如何 git remote prune 只是一个特定的远程分支?
【发布时间】:2016-12-27 03:22:18
【问题描述】:

我的一个同事“重用”了一个分支名称,所以每次拉取时,我都会收到一条错误消息:

error: 'refs/remotes/origin/branch' exists; cannot create 'refs/remotes/origin/branch/subbranch'
...
error: some local refs could not be updated; try running 
 'git remote prune origin' to remove any old, conflicting branches

问题是,我不想进行大规模的远程修剪 - 我很偏执,我想保留这些本地参考,以防其他同事以新的有趣方式搞砸了。

有没有一种方法可以只修剪有问题的分支,而不修剪所有其他在本地存储库中愉快地作为远程引用的分支?

【问题讨论】:

  • 您想要保留的分支是否已在任何地方合并?如果是这样,则无需专门保留对它们的引用,您可以随时返回这些提交。 (即使没有,提交也会一直存在,直到垃圾回收发生。)

标签: git git-remote


【解决方案1】:

如果你使用git branch-r选项,看起来你可以专门删除本地引用分支:

git branch -r --delete origin/branch

在此之后,可以适当地创建新分支,并且 fetch 和 pull 发生而不会出错。 (并且git remote prune --dry-run origin 仍然报告要修剪的分支。)

【讨论】:

    猜你喜欢
    • 2013-12-05
    • 2018-07-27
    • 2021-07-28
    • 1970-01-01
    • 2020-11-23
    • 2017-07-05
    • 2020-04-30
    相关资源
    最近更新 更多