3

从大约一个月前开始,每次我发出 'git pull' 时,我的 'git branch -a' 上都会有一堆 remotes/origin/pr/* 分支,这些分支直接映射到拉取请求的数量曾经在这个 repo 中打开过。执行“git remote prune origin”可以清理它们。

拉之前:

C:\experimental [develop]> git branch -a
* develop
  feature/291
  master
  remotes/origin/HEAD -> origin/master

拉 :

C:\experimental [develop]> git pull
From https://github.com/.../experimental
 * [new ref]         refs/pull/1/head -> origin/pr/1
 * [new ref]         refs/pull/10/head -> origin/pr/10
 * [new ref]         refs/pull/100/head -> origin/pr/100
 * [new ref]         refs/pull/101/head -> origin/pr/101
 * [new ref]         refs/pull/102/head -> origin/pr/102
 * [new ref]         refs/pull/103/head -> origin/pr/103
...
 * [new ref]         refs/pull/103/head -> origin/pr/382

拉后:

C:\experimental [develop]> git branch -a
* develop
  feature/291
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/pr/1
  remotes/origin/pr/10
  remotes/origin/pr/100
  remotes/origin/pr/101
  remotes/origin/pr/102
  remotes/origin/pr/103
...
  remotes/origin/pr/382

清理 :

C:\experimental [develop]> git remote prune origin
Pruning origin
URL: https://github.com/.../experimental.git
 * [pruned] origin/pr/1
 * [pruned] origin/pr/10
 * [pruned] origin/pr/100
 * [pruned] origin/pr/101
 * [pruned] origin/pr/102
 * [pruned] origin/pr/103
...
 * [pruned] origin/pr/382

清理后:

C:\experimental [develop]> git branch -a
* develop
  feature/291
  master
  remotes/origin/HEAD -> origin/master

如何阻止最初的“git pull”将它们拉下来?它只是在大约一个月前才开始发生。

谢谢。

4

2 回答 2

7

可能您遵循了如何在本地签出拉取请求的建议(请参阅https://help.github.com/articles/checking-out-pull-requests-locally)。要摆脱这个,只需删除该行

fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

从你的.git/config.

于 2013-07-14T22:08:13.933 回答
1

不知何故,它被添加到我的系统级 git 配置中。

正如您所发现的,这可能是 Windows(或 Mac?)的 GitHub,它提供了增强的--system配置,包括:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

(您可以用 确认git config --get-all remote.origin.fetch。)

如果您没有发现origin/prrefs 有用,删除该refs/pull行确实可以解决问题。我个人觉得它们很有用,所以prune你发现的行为令人沮丧:

在旧版本的 Git 中,如果该refs/pull行出现在refs/headsa行之后,remote prune则会删除origin/pr参考;换行让origin/pr裁判生存。

该错误已在Git 1.9.2中修复:

 * "git fetch --prune", when the right-hand-side of multiple fetch
   refspecs overlap (e.g. storing "refs/heads/*" to
   "refs/remotes/origin/*", while storing "refs/frotz/*" to
   "refs/remotes/origin/fr/*"), aggressively thought that lack of
   "refs/heads/fr/otz" on the origin site meant we should remove
   "refs/remotes/origin/fr/otz" from us, without checking their
   "refs/frotz/otz" first.

   Note that such a configuration is inherently unsafe (think what
   should happen when "refs/heads/fr/otz" does appear on the origin
   site), but that is not a reason not to be extra careful.
于 2014-10-17T06:23:01.483 回答