git - 为本地浅拷贝切换 git 标签/分支
问题描述
我正在尝试在本地浅层 git 存储库中从一个标签/分支切换到另一个标签/分支。然而,我注意到一些奇怪的行为。
# Initial creation of the repository
git init localrepo
git fetch --no-tag --depth 1 <repo-url> <branch/tag>
git checkout -b shallow --no-track FETCH_HEAD
# Switching to a new branch/tag
git fetch --no-tag --depth 1 <repo-url> <branch/tag>
git reset --hard FETCH_HEAD
我不确定这是否是正确的方法——但我注意到了一些奇怪的事情。当我切换到新的分支/标签时,文件.git/shallow
修订开始堆积。
有没有办法以某种方式重置 ```.git/shallow`` 文件,还是缺少其他东西?
解决方案
By default, Git clones the entire repository and therefore has a complete list of all the objects. With a shallow clone, the repository contains revisions back to one or more shallow points, and the approach you're using creates a new shallow point.
So what you're seeing is that Git is tracking that in each of those cases, it has the objects only back to those shallow points. If you removed the shallow points, your repository would be missing objects it was supposed to have, so you don't want to remove them.
Git is not designed to delete objects that are referenced, so as long as you have something in your repository (including the reflog) referencing those objects, they won't be pruned. If you desperately need your local repository to be as small as possible, you'll need to perform a fresh shallow clone. Otherwise, there's no harm in the current approach (other than the inefficiency of fetching into a shallow clone) and you're probably fine.
推荐阅读
- c++ - 从 QGraphicsScene 更新 QGraphicsView 的正确方法
- javascript - xpath 文档评估包含此 OR
- workbox - 如何检测 Workbox.register 预缓存请求失败?
- ios - SWIFT 中类似于 UIColor.systemgray 的任何标准字符串
- azure - Azure 和本地 Active Directory 之间的同步/删除用户
- javascript - 动态更改 Bootstrap 4 Toggles 的标签
- docker - 如何使用 dockerfile 将文件从主机复制到新的 docker 映像,这些文件作为容器上的卷共享?
- apache2 - Apache2:如何避免一个网站默认回复?
- java - 变量在执行操作后不改变其值
- docker - 如何在 chrome docker 映像上从本地运行 testcafe