scalopus
scalopus

Reputation: 2720

Compact Git repository with history depth

In Git, there is a command git clone --depth=<depth> to retrieve historical data only specific length. there are also a command to gather more historical data by use git fetch --depth=<depth>.

How about when we want to free some spaces from large repository? I know that we may use git gc or git prune but are there other way to specific like --depth=<depth> to reduce number of commit store in local repository? AND it also should keep SHA1 to be able continue to working with it.

Upvotes: 8

Views: 2412

Answers (1)

VonC
VonC

Reputation: 1329652

The easiest way would be to:

  • delete entirely the current local repo
  • git clone --depth=n /url/of/remote/repo

That would clone the last n commits, while allowing fetch/pull/psuh to still work with the remote repo.

since Git 2.5, you can fetch a single commit, but unless that commit is the latest one (which is like a git clone --depth=1), that would not allo for fetch/pull/push.

The other approach to make sure a given local repo is as lean as possible is to use a combination of gc/prune/repack:

git gc --aggressive
git repack -Ad       # kills in-pack garbage
git prune --progress # kills loose garbage

Upvotes: 4

Related Questions