git 每次获取后更改远程分支的问题
git issue with remote branches changed after each fetch
我使用 git fetch <remote> --depth=<N>
解决了将远程添加到我的本地存储库的超时问题。在不指定深度的情况下尝试 git fetch <remote>
会超时。所以我尝试了 git fetch <remote> --depth=10
然后重复 fetch
越来越多,每次都稳步增加深度,直到我终于能够得到整个东西(即增加深度检索零对象)。之后我 运行 git fetch <remote> --unshallow
其中 is supposed to convert the remote back to a non-shallow remote copy.
这是我的问题。完成所有这些之后,我不确定我的本地存储库是否处于 same/equivalent 状态,如果我刚开始时刚刚完成 git fetch <remote>
并且它没有超时。每次我 git fetch <remote>
它总是报告相同的 "new" 和 "updated" b运行ches.
这是怎么回事,我该如何纠正?
我唯一能想到尝试但实际上没有尝试过的方法是删除遥控器并重新添加。我害怕不得不重新开始。这是一个非常大的存储库,花了很长时间才达到这一点。如果我在此期间避免 git gc
,删除并重新添加远程是否允许 b运行ches 重置而无需再次下载所有提交?
这是我所做的和结果。
每次我 git fetch <remote>
现在,无论我尝试什么,我都会得到这个输出:
Fetching <remote>
From ssh://<url>
+ 3603285...775e0fe Feature/A -> <remote>/Feature/A (forced update)
+ 6303337...de89a23 Feature/B -> <remote>/Feature/B (forced update)
* [new branch] feature/C -> <remote>/feature/C
* [new branch] feature/D -> <remote>/feature/D
* [new branch] feature/E -> <remote>/feature/E
* [new branch] feature/F -> <remote>/feature/F
* [new branch] feature/G -> <remote>/feature/G
* [new branch] feature/H -> <remote>/feature/H
每次输出相同。其他遥控器不会像这样。它只出现在这个遥控器上,b运行ch 指针实际上从未前进,每个 fetch
都试图再次前进。输出中从来没有任何实际错误。
我已经验证这些b运行ches都存在于远程服务器中并且没有被删除。但是,检查远程仓库上 b运行ch Feature/A
的整个提交历史,它根本不包含提交 3603285
。
git config --get remote.<remote>.fetch
的输出:
+refs/heads/*:refs/remotes/<remote>/*
git remote show <remote>
的部分输出:
Remote branches:
feature/X tracked
feature/Y tracked
feature/A tracked
feature/B tracked
refs/remotes/<remote>feature/C stale (use 'git remote prune' to remove)
refs/remotes/<remote>feature/D stale (use 'git remote prune' to remove)
refs/remotes/<remote>feature/E stale (use 'git remote prune' to remove)
refs/remotes/<remote>feature/F stale (use 'git remote prune' to remove)
refs/remotes/<remote>feature/G stale (use 'git remote prune' to remove)
refs/remotes/<remote>feature/H stale (use 'git remote prune' to remove)
我尝试过但没有解决这个问题的方法:
git fsck
(不报任何问题)
git fetch <remote> --unshallow
(报告存储库已经完成)
git gc
(未报告错误,运行 两次产生相同的输出)
git remote prune <remote>
(删除 b运行ches C
到 H
,但它们会在下一个 fetch
时重新添加)
git fetch --all --prune
git fetch --all --prune
的输出有点不同(也是每次,无论我尝试什么):
Fetching <remote>
From ssh://<url>
x [deleted] (none) -> <remote>/Feature/C
x [deleted] (none) -> <remote>/Feature/D
x [deleted] (none) -> <remote>/Feature/E
x [deleted] (none) -> <remote>/Feature/F
x [deleted] (none) -> <remote>/Feature/G
x [deleted] (none) -> <remote>/Feature/H
+ 3603285...775e0fe Feature/A -> <remote>/Feature/A (forced update)
+ 6303337...de89a23 Feature/B -> <remote>/Feature/B (forced update)
* [new branch] feature/C -> <remote>/feature/C
* [new branch] feature/D -> <remote>/feature/D
* [new branch] feature/E -> <remote>/feature/E
* [new branch] feature/F -> <remote>/feature/F
* [new branch] feature/G -> <remote>/feature/G
* [new branch] feature/H -> <remote>/feature/H
如果我查看 b运行ch <remote>/Feature/A
我得到提交 3603285
而不是 775e0fe
,即使在远程服务器上,Feature/A
指向775e0fe
和 3603285
在它的历史中是无处可寻的。我也可以通过提交字符串直接检查 775e0fe
没有问题。这一系列命令产生的输出让我感到惊讶(也是每次,无论我尝试什么):
$ git checkout <remote>/Feature/A
HEAD is now at 3603285
$ git checkout -b Feature/A
$ git merge 775e0fe
Already up-to-date.
这是一个文件系统大小写折叠问题,所以它与浅层部分无关(这是好消息/坏消息)。
我看到你这里有 feature/<name>
和 Feature/<name>
,有小写和大写的 F。你的 Git 在你的存储库中设置它们,但是一旦它创建了一个目录案例,分支名称与其他案例放在同一目录中。你的 Git 然后认为那些是错误的:它必须销毁错误的分支并创建正确的分支,它确实这样做了,但是你仍然有错误的名称,因为你的 OS once再次折叠大小写并将所有内容写入现有的其他大小写目录。
通常的解决方案是使用不折叠大小写的OS(或文件系统),或者修复上游以使用单个大小写。
如果那不可能,我有一个想法,我从未测试过,但应该可行:你可以拆分你的 fetch
URL。这有各种缺点,主要的缺点是您必须偶尔手动 运行 git ls-remote
并检查是否需要更新 URL 映射。 (最好使用一种更常用的解决方案。)
我使用 git fetch <remote> --depth=<N>
解决了将远程添加到我的本地存储库的超时问题。在不指定深度的情况下尝试 git fetch <remote>
会超时。所以我尝试了 git fetch <remote> --depth=10
然后重复 fetch
越来越多,每次都稳步增加深度,直到我终于能够得到整个东西(即增加深度检索零对象)。之后我 运行 git fetch <remote> --unshallow
其中 is supposed to convert the remote back to a non-shallow remote copy.
这是我的问题。完成所有这些之后,我不确定我的本地存储库是否处于 same/equivalent 状态,如果我刚开始时刚刚完成 git fetch <remote>
并且它没有超时。每次我 git fetch <remote>
它总是报告相同的 "new" 和 "updated" b运行ches.
这是怎么回事,我该如何纠正?
我唯一能想到尝试但实际上没有尝试过的方法是删除遥控器并重新添加。我害怕不得不重新开始。这是一个非常大的存储库,花了很长时间才达到这一点。如果我在此期间避免 git gc
,删除并重新添加远程是否允许 b运行ches 重置而无需再次下载所有提交?
这是我所做的和结果。
每次我 git fetch <remote>
现在,无论我尝试什么,我都会得到这个输出:
Fetching <remote>
From ssh://<url>
+ 3603285...775e0fe Feature/A -> <remote>/Feature/A (forced update)
+ 6303337...de89a23 Feature/B -> <remote>/Feature/B (forced update)
* [new branch] feature/C -> <remote>/feature/C
* [new branch] feature/D -> <remote>/feature/D
* [new branch] feature/E -> <remote>/feature/E
* [new branch] feature/F -> <remote>/feature/F
* [new branch] feature/G -> <remote>/feature/G
* [new branch] feature/H -> <remote>/feature/H
每次输出相同。其他遥控器不会像这样。它只出现在这个遥控器上,b运行ch 指针实际上从未前进,每个 fetch
都试图再次前进。输出中从来没有任何实际错误。
我已经验证这些b运行ches都存在于远程服务器中并且没有被删除。但是,检查远程仓库上 b运行ch Feature/A
的整个提交历史,它根本不包含提交 3603285
。
git config --get remote.<remote>.fetch
的输出:
+refs/heads/*:refs/remotes/<remote>/*
git remote show <remote>
的部分输出:
Remote branches:
feature/X tracked
feature/Y tracked
feature/A tracked
feature/B tracked
refs/remotes/<remote>feature/C stale (use 'git remote prune' to remove)
refs/remotes/<remote>feature/D stale (use 'git remote prune' to remove)
refs/remotes/<remote>feature/E stale (use 'git remote prune' to remove)
refs/remotes/<remote>feature/F stale (use 'git remote prune' to remove)
refs/remotes/<remote>feature/G stale (use 'git remote prune' to remove)
refs/remotes/<remote>feature/H stale (use 'git remote prune' to remove)
我尝试过但没有解决这个问题的方法:
git fsck
(不报任何问题)git fetch <remote> --unshallow
(报告存储库已经完成)git gc
(未报告错误,运行 两次产生相同的输出)git remote prune <remote>
(删除 b运行chesC
到H
,但它们会在下一个fetch
时重新添加)git fetch --all --prune
git fetch --all --prune
的输出有点不同(也是每次,无论我尝试什么):
Fetching <remote>
From ssh://<url>
x [deleted] (none) -> <remote>/Feature/C
x [deleted] (none) -> <remote>/Feature/D
x [deleted] (none) -> <remote>/Feature/E
x [deleted] (none) -> <remote>/Feature/F
x [deleted] (none) -> <remote>/Feature/G
x [deleted] (none) -> <remote>/Feature/H
+ 3603285...775e0fe Feature/A -> <remote>/Feature/A (forced update)
+ 6303337...de89a23 Feature/B -> <remote>/Feature/B (forced update)
* [new branch] feature/C -> <remote>/feature/C
* [new branch] feature/D -> <remote>/feature/D
* [new branch] feature/E -> <remote>/feature/E
* [new branch] feature/F -> <remote>/feature/F
* [new branch] feature/G -> <remote>/feature/G
* [new branch] feature/H -> <remote>/feature/H
如果我查看 b运行ch <remote>/Feature/A
我得到提交 3603285
而不是 775e0fe
,即使在远程服务器上,Feature/A
指向775e0fe
和 3603285
在它的历史中是无处可寻的。我也可以通过提交字符串直接检查 775e0fe
没有问题。这一系列命令产生的输出让我感到惊讶(也是每次,无论我尝试什么):
$ git checkout <remote>/Feature/A
HEAD is now at 3603285
$ git checkout -b Feature/A
$ git merge 775e0fe
Already up-to-date.
这是一个文件系统大小写折叠问题,所以它与浅层部分无关(这是好消息/坏消息)。
我看到你这里有 feature/<name>
和 Feature/<name>
,有小写和大写的 F。你的 Git 在你的存储库中设置它们,但是一旦它创建了一个目录案例,分支名称与其他案例放在同一目录中。你的 Git 然后认为那些是错误的:它必须销毁错误的分支并创建正确的分支,它确实这样做了,但是你仍然有错误的名称,因为你的 OS once再次折叠大小写并将所有内容写入现有的其他大小写目录。
通常的解决方案是使用不折叠大小写的OS(或文件系统),或者修复上游以使用单个大小写。
如果那不可能,我有一个想法,我从未测试过,但应该可行:你可以拆分你的 fetch
URL。这有各种缺点,主要的缺点是您必须偶尔手动 运行 git ls-remote
并检查是否需要更新 URL 映射。 (最好使用一种更常用的解决方案。)