我的 Git 中添加了很多 Remote 。每个 Remote 都是一个开发人员的存储库。每天我都fetch --all
来查看他们创建的任何准备好审查的新分支。
但是,开发人员可以将“私有(private)”分支推送到远程。比如说,所有以下划线前缀命名的分支都没有准备好审查,而其他分支已经准备好审查。
当执行 git fetch --all
时,我的 Git 图(通过 /libexec/git-core/git-gui
)将看到所有分支,无论是否他们是否有下划线前缀。它使图表复杂化。
我希望 git fetch
忽略那些下载到我本地 Git 的 _XXXX
分支。所以当我查看 Git 图时,它就像:
- 显示分支:
RemoteA/Branch1
,RemoteB/Branch1
,RemoteB/Branch2
- 忽略分支:
RemoteA/_Branch2
,RemoteB/_Branch3
我该怎么做?
最佳答案
Git v2.29.0 更新
与 negative refspecs ,1在Git v2.29中加入,你可以在不改变同事习惯的情况下实现你的初衷。
对于每个同事的远程,添加一个否定的 refspec(即以 ^
为前缀)以排除以 _
为前缀的分支。这松散地改编自 the unit test for .git/config
和 the one for negative patterns .请参阅下面“Fred 的” Remote 代码块中的最后一行。
[remote "fred"]
url = something.git
fetch = +refs/heads/*:refs/remotes/fred/*
fetch = ^refs/heads/_*
您有两个选项可以在命令行上为 fred
进行设置:
git config --add remote.fred.fetch '^refs/heads/_*'
git remote set-branches --add fred '^refs/heads/_*'
原始答案
扩展 VonC's excellent answer使用特殊的“审查”文件夹,2 您可以修改您同事的 Remote 的 .git/config
条目。这是 the relevant documentation .
曾经的地方
[remote "fred"]
url = something.git
fetch = +refs/heads/*:refs/remotes/fred/*
你可以把它改成
[remote "fred"]
url = something.git
fetch = +refs/heads/review/*:refs/remotes/fred/review/*
fetch = +refs/heads/other_pattern/*:refs/remotes/fred/other_pattern/*
fetch = +refs/heads/specific_branch:refs/remotes/fred/specific_branch
这样做之后,您可能必须清理对已经获取的引用的引用,但是 future 的 git fetch --all
或 git fetch fred
将不更新您指定的模式之外的任何内容。
1 关于负面 refspecs 的文档有点少,埋在 a longer passage 中。 , 所以最好看的地方是 in Git's history或在 VonC's answer to a different question ,他将相关部分放在一起。
2 或者您需要的任意数量的特殊或有趣的文件夹和分支。
关于git - 使用 `git fetch --all` 跳过将一些分支/标签复制到本地 Git,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26623867/