I'm having an issue when using Azure Releases to pull a repo to a remote machine.
When going to the .git/objects/pack folder, I can see multiple pack files (These are currently 5.1gb) - I deleted the repo and re-ran the release and it's still doing it. Before I deleted it I had over 10 of these files.
On the same machine, I also tried putting on SourceTree and using pulling the repo down with this. Both the SourceTree git folder & my local git folders don't contain multiple pack files, but only one.
I've put my Powershell Script that I am using here:
$resourcesPath = "`$(ResourcesPath)"
$environment = "`$(EnvironmentShortName)"
$path = Join-Path -Path $resourcesPath -ChildPath $environment
$resourceCommit = (Get-Content -Path "`$(System.DefaultWorkingDirectory)/resources/Metropolis-Resources/commit" -First 1).Trim()
$repo = "Metropolis-Resources"
$env:GIT_REDIRECT_STDERR = '2>&1'
Write-Output "Checking out commit: $resourceCommit"
if(-not (Test-Path -LiteralPath $path))
{
New-Item -Path $path -ItemType Directory -Force
$doInit = $true
}
Write-Host "Setting path: $path"
Set-Location -LiteralPath $path
if($doInit)
{
Write-Host "Init Git for some reason?"
& git init
& git remote add origin "https://AzureDevops:`$(System.Accesstoken)@metropolisrpc.visualstudio.com:/Metropolis/_git/$repo"
}
else
{
& git remote set-url origin "https://AzureDevops:`$(System.Accesstoken)@metropolisrpc.visualstudio.com:/Metropolis/_git/$repo"
}
Write-Host "Resetting head..."
git clean -xdf
git reset --hard
Write-Host "Fetching commit..."
& git fetch origin $resourceCommit
if(-not $doInit)
{
Write-Host "Generating diff..."
& git diff HEAD..$resourceCommit --stat
}
& git checkout $resourceCommit
CodePudding user response:
Multiple .pack
files are normal. When using the multi-pack-index feature, they should be quite efficient as well (though they will obviously occupy more space). Depending on particular circumstances, they could even be more efficient than single pack files (though I'd want to measure this before making any solid claims here).
To squash multiple pack files into fewer (or even just one) pack file, use git repack
, or git gc
which runs git repack
for you. Note that doing this is expensive (in CPU time and energy if nothing else) and if there's little gained by repacking, you've wasted most of this expense. If a lot is gained, it's worthwhile.
The newfangled git maintenance
command can be used to schedule git gc
operations for times when nothing else is going on.
Git normally runs git gc --auto
on its own, which spins off a background git gc
whenever Git thinks this would be profitable.