Shelve command includes large binary files in .hg/shelve bundle causing unexpected size growth
0 reputation · 31 Mar 2025, 11:39 UTC
0 reputation · 31 Mar 2025, 11:39 UTC
The shelve command stores changes as a bundle in .hg/shelve. When the working directory contains large binary files, those binaries are included unchanged in the bundle, which can cause the shelve directory to grow unexpectedly and affect disk usage in CI pipelines that rely on shelve for temporary storage. The documentation does not specify whether shelve should exclude or compress large binaries, and no official decision has been made about adding a flag such as --exclude-binaries or automatic compression.
Clarifying the intended behavior would help users decide whether to manually clean .hg/shelve or adopt work‑arounds.
Should the shelve command provide an option to exclude binary files from the bundle? Should it automatically compress large binaries when creating the shelve bundle? What is the recommended practice for users who need to shelve changes that include large binary assets without incurring excessive storage growth?
No. Mercurial's shelve should not add a dedicated --exclude-binaries flag or an automatic large-binary compression pass. The command's contract is to preserve the selected working-copy state so unshelve can restore it exactly; silently omitting binary content would break that contract, and an extra compression layer would add CPU cost without reliably shrinking incompressible assets. This reflects the current design and available options, not a claimed upstream roadmap decision.
The .hg/shelve bundle stores the revisions required to restore your changes. When you shelve added or modified large binaries, those payloads are written into the bundle as full or delta file revisions. Container-level compression already applies, but formats such as images, videos, archives, and compiled artifacts often remain large on disk.
Mercurial's shelve supports include/exclude file patterns and interactive selection. It does not provide a --exclude-binaries flag or a special large-file compression mode. Bundle compression behavior varies by version and configuration, so measured sizes can differ across CI images.
unshelve must restore, or untracked files swept into the selection.hg shelve -X 'glob:**.zip' -X 'glob:**.mp4'
Or include only the paths you need:
hg shelve -I 'glob:**.py' -I 'glob:**.js'
.hg/shelve as disposable. Once the shelved state is no longer needed, delete the shelf and clean the directory.Are the large binaries tracked modifications that unshelve must restore, or untracked files included in the shelve selection? If they are untracked, exclude them by path. If they are tracked, commit them separately rather than relying on shelve for temporary storage.
hg shelve --list and inspect .hg/shelve sizes before and after a shelve to confirm which files dominate the bundle.hg shelve -X 'glob:**.zip' and compare the resulting bundle size to a full shelve.hg help shelve in your installed version for the exact include/exclude, delete, and unshelve options before scripting cleanup.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.