为什么gitlfs migrate 后commit 的数量会增加?
Why does the number of commits increase after git lfs migrate?
我在大型存储库上尝试了 运行 git lfs migrate import --everything --include="*.dll"
。在我 运行 之前,大约有 70k 次提交。在 运行 迁移(以及到期的 reflog 和修剪等)之后 git rev-list --all --count
显示大约 130k 提交。为什么添加了这么多提交,这些提交是什么?
检查 issue 3238 是否不是您的原因。
简而言之,一个标签可能仍然引用一个旧的提交(并且它的所有 parents 仍然会被 git rev-list
计算)
Search if there are some tags that are still pointing to old OIDs that are suppposed to get migrated by git lfs migrate
.
You get such information into the --object-map=mapping_file.map.txt
file.
Following script shall be executed within git repository. It will not make any modification in the repository, until you un-echo the git tag command...
MAP_FILE=../mapping_file.map.txt
git for-each-ref | grep tags | while read -r oid type tag; do
while IFS=, read -r old_oid new_oid; do
if [[ "$oid" == "$old_oid" ]]; then
echo TAG $tag still pointing to old_oid $old_oid instead of $new_oid
echo git tag -f $(basename $tag) $new_oid
fi
done < $MAP_FILE
done
注意,映射文件来自 this comment:
Under some specific conditions, which I don’t know, lfs migrate import
is not able to move refs (tags, branches) from the old commit to the new created one.
As a consequence of this, "git gc
" can’t remove the old commits.
Our database are unfortunately not sharable, but I can try to describe our way to get rid of these old commits.
- Create a map file (
--object-map=
) while running lfs migrate import
to get a correlation between old commits and new commits created by lfs.
- Collect all commits from your original database and the working lfs database (
git rev-list –all
)
- Identify all so-called double commits. These are commits existing in the original and the working lfs database.
- Check these double commits for still existing refs (
git show –s
) and move every found ref manually or by script to the corresponding new commit (from your created map file) with these git commands: git tag –f
, git update-ref
.
- Run
git gc –prune=now
and check your commit count in your working lfs database
我在@torek 的评论的帮助下设法解决了这个问题。正如上面评论中提到的,git rev-list --branches --tags
列出了正确的提交数。
存储库是通过使用 git tfs 将 TFVC 存储库转换为 git 创建的。 运行 git for-each-ref
在 refs/remotes/tfs
下列出了一堆引用,但在 运行 git remote -v
时没有显示,因为它们被列为 [=22] =]提交。因此,这些可能引用了一堆未被 git lfs migrate
重写的旧提交,并且显然这些引用未被 git lfs migrate 更新,这可能是预期的。
使用 git update-ref -d
删除所有这些引用,然后再执行一次 gc,似乎已经解决了问题并且存储库恢复到其原始提交数。
我在大型存储库上尝试了 运行 git lfs migrate import --everything --include="*.dll"
。在我 运行 之前,大约有 70k 次提交。在 运行 迁移(以及到期的 reflog 和修剪等)之后 git rev-list --all --count
显示大约 130k 提交。为什么添加了这么多提交,这些提交是什么?
检查 issue 3238 是否不是您的原因。
简而言之,一个标签可能仍然引用一个旧的提交(并且它的所有 parents 仍然会被 git rev-list
计算)
Search if there are some tags that are still pointing to old OIDs that are suppposed to get migrated by
git lfs migrate
.
You get such information into the--object-map=mapping_file.map.txt
file.
Following script shall be executed within git repository. It will not make any modification in the repository, until you un-echo the git tag command...
MAP_FILE=../mapping_file.map.txt
git for-each-ref | grep tags | while read -r oid type tag; do
while IFS=, read -r old_oid new_oid; do
if [[ "$oid" == "$old_oid" ]]; then
echo TAG $tag still pointing to old_oid $old_oid instead of $new_oid
echo git tag -f $(basename $tag) $new_oid
fi
done < $MAP_FILE
done
注意,映射文件来自 this comment:
Under some specific conditions, which I don’t know,
lfs migrate import
is not able to move refs (tags, branches) from the old commit to the new created one.
As a consequence of this, "git gc
" can’t remove the old commits.
Our database are unfortunately not sharable, but I can try to describe our way to get rid of these old commits.
- Create a map file (
--object-map=
) while runninglfs migrate import
to get a correlation between old commits and new commits created by lfs.- Collect all commits from your original database and the working lfs database (
git rev-list –all
)- Identify all so-called double commits. These are commits existing in the original and the working lfs database.
- Check these double commits for still existing refs (
git show –s
) and move every found ref manually or by script to the corresponding new commit (from your created map file) with these git commands:git tag –f
,git update-ref
.- Run
git gc –prune=now
and check your commit count in your working lfs database
我在@torek 的评论的帮助下设法解决了这个问题。正如上面评论中提到的,git rev-list --branches --tags
列出了正确的提交数。
存储库是通过使用 git tfs 将 TFVC 存储库转换为 git 创建的。 运行 git for-each-ref
在 refs/remotes/tfs
下列出了一堆引用,但在 运行 git remote -v
时没有显示,因为它们被列为 [=22] =]提交。因此,这些可能引用了一堆未被 git lfs migrate
重写的旧提交,并且显然这些引用未被 git lfs migrate 更新,这可能是预期的。
使用 git update-ref -d
删除所有这些引用,然后再执行一次 gc,似乎已经解决了问题并且存储库恢复到其原始提交数。