feat: add prune command to remove superseded versions - #189
Merged
Conversation
tr1v3r
marked this pull request as ready for review
August 26, 2026 07:44
Each Go installation takes up a few hundred megabytes, and upgrading within a minor series (e.g. `g install 1.24` picking up the latest patch) leaves the older patch versions behind until they are uninstalled one by one. `g prune` removes versions superseded within their minor series, keeping the newest version of each series. The version currently in use is never removed. `--dry-run` previews what would be removed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Each installed Go version takes up a few hundred megabytes. Upgrading within a minor series (e.g.
g install 1.24resolving to the latest 1.24.x) leaves the older patch versions installed, and today they can only be reclaimed by callingg uninstallonce per version.This adds a
g prunecommand that removes superseded versions automatically.Behavior
major.minorseries and keeps only the newest version of each series (e.g. with1.19.10,1.19.13,1.20.5,1.24.5,1.24.6installed,1.19.10and1.24.5are removed).g uninstalltoday — worth a follow-up, but kept out of this PR to stay minimal.)1.25rc1is pruned once1.25.0is installed).--dry-runprints what would be removed without deleting anything.Nothing to remove.$ g ls 1.19.10 1.19.13 1.20.4 * 1.24.3 1.24.6 $ g prune --dry-run Would remove 1.19.10 $ g prune Removed 1.19.10Implementation
cli/prune.go: thin action overlistLocalVersions+ a puresuperseded()helper (versions are sorted ascending, so a version is superseded when its successor belongs to the same minor series).version/version.go: addsMajor()/Minor()accessors for series grouping.cli/commands.go: registers theprunecommand.README.md,README_CN.md).cli/prune_test.go: table-driven tests covering grouping, in-use protection, prerelease ordering, and major-series independence.Testing
go build ./...,go vet ./cli/ ./version/,gofmtclean.go test ./cli/ ./version/pass.collector,pkg/http,pkg/sdk/githubcurrently fail in my environment on both this branch and pristinemaster(they hit real network URLs behind a corporate proxy), so they are unrelated to this change.G_HOME(create version dirs, symlinkgoto an older patch, rung prune/g prune --dry-run/g ls).