【发布时间】:2021-09-02 14:41:58
【问题描述】:
我需要git pull 远程存储库中的所有分支,但我想排除一个特定的分支。这是我的尝试,基于我在 https://git-scm.com/docs/git-pull 阅读的内容,查看部分,排除分支:
$ git ls-remote | grep Bad-branch
From git@gitlab.mycompany.com:analytics/path/repo.git
181647289762f00110d67199adec2559a5dbbbe6 refs/heads/Bad-branch
$ git pull origin ^refs/heads/Bad-branch
There are no candidates for merging among the refs that you just fetched.
Generally this means that you provided a wildcard refspec which had no
matches on the remote end.
如您所见,这是行不通的。如何指定要排除的分支?
我也参考了这些帖子,但我不想修改配置文件,只是一个临时命令行规范以忽略分支,直到它被删除。
- Is there a way to git ignore entire branches?
- How to ignore some branches/tags being copied to local git when do git fetch --all
编辑:为了清楚起见,这里是中断的实际 git 调用,因为我在 Windows 上,从分支名称生成的路径名给出的文件名太长:
$ git pull
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 3 (delta 2), pack-reused 0
Unpacking objects: 100% (3/3), 384 bytes | 16.00 KiB/s, done.
error: cannot lock ref 'refs/remotes/origin/TCCFOUR-19049-Algo-ProductionModuleLowDeltaT.R-distribution.supply.temperature.in.control.exception-displayed-as-YesNo-in-RDR-but-TrueFalse-in-analytic': Unable to create 'C:/Users/IRINZN/work/projects/analytic-r-docker-setup/analytic-r-cc4-algorithms/.git/refs/remotes/origin/TCCFOUR-19049-Algo-ProductionModuleLowDeltaT.R-distribution.supply.temperature.in.control.exception-displayed-as-YesNo-in-RDR-but-TrueFalse-in-analytic.lock': Filename too long
【问题讨论】:
-
我们说的是多少个分支?
-
@ScottHunter 在这种情况下只有一个分支。问题是有人创建了一个太长的分支名称,对于 Windows 路径来说太长了(但在 Linux/BSD 系统上还可以)。在等待作者删除它的同时,我希望能够同步我的存储库。
-
@matt 好吧,我的正常工作流程是进行拉动,但现在它正在中断。我想我可以修改我的拉取请求以不中断。 git-pull 文档引用了排除 refspecs 的能力。但如果我真的只需要 fetch 而不是 pull,并且可以排除 fetch 调用,我会采取这样的解决方案。
-
但关键是,使用 fetch 您不需要排除任何内容,因为它对“您的”文件(本地分支中的文件)没有任何影响。所以没问题。我无法理解您认为自己确实有什么实际问题。当然,也许我只是太慢了。
-
让您的同事创建一个较短的分支名称,然后删除较长的分支名称,然后责备他或她不知道您的问题跟踪器和 git 分支之间的区别。您可以在问题跟踪器中写一篇文章,分支名称应该简洁明了,您不需要在其名称中写下分支的完整理由。您也可以运行
git config --system core.longpaths true,它告诉 git 尝试使用更长的文件路径,但该分支名称仍然是假的。
标签: git