简体   繁体   English

GIT迁移回购比原来小

[英]GIT migrated repo is way smaller than original

I have a repository stored on filesystem that I need to migrate to a HTTPS git repository. 我有一个存储在文件系统上的存储库,我需要将其迁移到HTTPS git存储库。 The issue is that the migrated repo is smaller that the original, 179M vs 545 MB to be precise. 问题是迁移的repo比原来的小,179M对545 MB是精确的。

This is how the original repo looks like: 这就是原始回购的样子:

$ tree -L 2 .git

.git/
├── branches
├── config
├── FETCH_HEAD
├── HEAD
├── hooks
├── index
├── logs
│   └── refs
├── objects
│   ├── incoming_1638816568970138516.pack
│   ├── incoming_2231423675192085195.pack
│   ├── incoming_252567842603709439.pack
│   ├── incoming_2956015230264054740.pack
│   ├── incoming_3048626775278812485.pack
│   ├── incoming_3322152774343971530.pack
│   ├── incoming_3707332777993276763.pack
│   ├── incoming_407171399829023385.pack
│   ├── incoming_4072000993266381297.pack
│   ├── incoming_4293432441900999175.pack
│   ├── incoming_4833572675284287989.pack
│   ├── incoming_4943537936436869872.pack
│   ├── incoming_5555086829860720971.pack
│   ├── incoming_5912835395946639495.pack
│   ├── incoming_7273182803237175093.pack
│   ├── incoming_7510898138918506599.pack
│   ├── incoming_7865231230366160752.pack
│   ├── incoming_8724975206375007218.pack
│   ├── incoming_8787762604831244623.pack
│   ├── incoming_9046531469688239004.pack
│   ├── info
│   └── pack
└── refs
    ├── heads
    ├── remotes
    └── tags


$ git branch -a

  cli
  max
  codefactoring
* master
  new-load-configuration
  new-loader
  plugins_dev
  remotes/origin/cli
  remotes/origin/max
  remotes/origin/codefactoring
  remotes/origin/master

$ du -sh .
545M    .

This is the migration procedure I've followed: 这是我遵循的迁移过程:

$ mkdir temp_dir && cd temp_dir
$ git clone --mirror /path/to/original/repo
$ cd /path/to/original/repo
$ git remote add new-origin  https://myuser@my.source.server/myuser/repo.git
$ git push new-origin --mirror

And then, if I look at the resulting repo size, it's 179MB. 然后,如果我看看最终的回购大小,那就是179MB。

Any idea of what is happening here? 知道这里发生了什么吗?

Thank you. 谢谢。

The information stored in the cloned repository is packed before the clone actually starts. 存储在克隆存储库中的信息在克隆实际启动之前打包。 That way, it's perfectly compressed and maintains a small size while containing all information of the original repository. 这样,它完全压缩并保持小尺寸,同时包含原始存储库的所有信息

The original repository however likely evolved over time, so it is possibly fragmented and cannot be packed as efficiently. 然而,原始存储库可能会随着时间的推移而发展,因此它可能是碎片化的,无法有效地打包。 Maybe it is not completely packed at all but contains still unoptimized objects or even no longer reachable objects. 也许它根本没有完全包装,但包含仍然未经优化的对象,甚至不再可达的对象。

You could try using git gc (or one of its more aggressive options) on the original repository to see if you can shrink it further. 您可以尝试在原始存储库上使用git gc (或其中一个更具攻击性的选项)来查看是否可以进一步缩小它。

The bottom line however is that if the clone process completed without errors, then the cloned repository will contain all the information of the original repository. 但最重要的是,如果克隆过程完成且没有错误,则克隆的存储库将包含原始存储库的所有信息。 That is, every commit and its data that is reachable using branches or tags will be included. 也就是说,将包括使用分支或标记可到达的每个提交及其数据。 So you should not need to worry about it. 所以你不必担心它。

I would say that the difference is because your original repository is a non-bare one while the migrated repository is a bare one. 我会说,不同之处在于您的原始存储库是非裸存储库,而迁移存储库是裸存储库。 Therefore 545MB includes the size of the working tree, which is missing in the migrated repo. 因此,545MB包括工作树的大小,迁移的仓库中缺少该大小。 Attributing all the size difference (545MB - 179MB = 366MB) to the working tree can be plausible for the following reasons: 由于以下原因,将所有大小差异(545MB - 179MB = 366MB)归因于工作树可能是合理的:

  1. Objects in the repository are compressed while in the working tree they are not. 存储库中的对象在工作树中被压缩,而不是。 Thus in a repository with a short enough history and/or strongly compressible contents the working tree can noticeably exceed the contents of .git . 因此,在具有足够短的历史和/或强可压缩内容的存储库中,工作树可以显着地超过.git的内容。

  2. Working tree may contain untracked files (eg build artifacts). 工作树可能包含未跟踪的文件(例如构建工件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM