| 1 |
= git-lfs-prune(1) |
| 2 |
|
| 3 |
== NAME |
| 4 |
|
| 5 |
git-lfs-prune - Delete old LFS files from local storage |
| 6 |
|
| 7 |
== SYNOPSIS |
| 8 |
|
| 9 |
[source,role=synopsis,subs="verbatim,quotes"] |
| 10 |
---- |
| 11 |
*git lfs prune* [_options_] |
| 12 |
---- |
| 13 |
|
| 14 |
== DESCRIPTION |
| 15 |
|
| 16 |
Deletes local copies of LFS files which are old, thus freeing up disk |
| 17 |
space. Prune operates by enumerating all the locally stored objects, and |
| 18 |
then deleting any which are not referenced by at least ONE of the |
| 19 |
following: |
| 20 |
|
| 21 |
* the current checkout |
| 22 |
* all existing stashes |
| 23 |
* a 'recent branch'; see <<_recent_files>> |
| 24 |
* a 'recent commit' on the current branch or recent branches; see |
| 25 |
<<_recent_files>> |
| 26 |
* a commit which has not been pushed; see <<_unpushed_lfs_files>> |
| 27 |
* any other worktree checkouts; see git-worktree(1) |
| 28 |
|
| 29 |
In general terms, prune will delete files you're not currently using and |
| 30 |
which are not 'recent', so long as they've been pushed i.e. the local |
| 31 |
copy is not the only one. |
| 32 |
|
| 33 |
The reflog is not considered, only commits. Therefore LFS objects that |
| 34 |
are only referenced by orphaned commits are always deleted. |
| 35 |
|
| 36 |
Note: you should not run `git lfs prune` if you have different |
| 37 |
repositories sharing the same custom storage directory; see |
| 38 |
git-lfs-config(5) for more details about `lfs.storage` option. |
| 39 |
|
| 40 |
In your Git configuration or in a `.lfsconfig` file, you may set |
| 41 |
`lfs.fetchexclude` to a comma-separated list of paths. If |
| 42 |
`lfs.fetchexclude` is defined, then any Git LFS files whose paths match |
| 43 |
one in that list will be pruned unless they are referenced by a stash or |
| 44 |
an unpushed commit. Paths are matched using wildcard matching as per |
| 45 |
gitignore(5). |
| 46 |
|
| 47 |
== OPTIONS |
| 48 |
|
| 49 |
`-d`:: |
| 50 |
`--dry-run`:: |
| 51 |
Don't actually delete anything, just report on what would have been done |
| 52 |
`-f`:: |
| 53 |
`--force`:: |
| 54 |
Prune all objects except unpushed objects, including objects required for |
| 55 |
currently checked out refs. Implies `--recent`. |
| 56 |
`--recent`:: |
| 57 |
Prune even objects that would normally be preserved by the |
| 58 |
configuration options specified below in <<_recent_files>>. |
| 59 |
`-c`:: |
| 60 |
`--verify-remote`:: |
| 61 |
Contact the remote and check that copies of reachable files we would delete |
| 62 |
definitely exist before deleting. See <<_verify_remote>>. |
| 63 |
`--no-verify-remote`:: |
| 64 |
Disables remote verification if lfs.pruneverifyremotealways was enabled in |
| 65 |
settings. See <<_verify_remote>>. |
| 66 |
`--verify-unreachable`:: |
| 67 |
When doing `--verify-remote` contact the remote and check unreachable |
| 68 |
objects as well. See <<_verify_remote>>. |
| 69 |
`--no-verify-unreachable`:: |
| 70 |
Disables remote verification of unreachable files if |
| 71 |
lfs.pruneverifyunreachablealways was enabled in settings. See |
| 72 |
<<_verify_remote>>. |
| 73 |
`--when-unverified=<halt,continue>`:: |
| 74 |
When `--verify-remote` cannot verify an object on the remote, either halt |
| 75 |
the execution or continue the deletion of verified objects. See |
| 76 |
<<_verify_remote>>. |
| 77 |
`-v`:: |
| 78 |
`--verbose`:: |
| 79 |
Report the full detail of what is/would be deleted. |
| 80 |
|
| 81 |
== RECENT FILES |
| 82 |
|
| 83 |
Prune won't delete LFS files referenced by 'recent' commits, in case you |
| 84 |
want to use them again without having to download. The definition of |
| 85 |
'recent' is derived from the one used by git-lfs-fetch(1) to download |
| 86 |
recent objects with the `--recent` option, with an offset of a number of |
| 87 |
days (default 3) to ensure that we always keep files you download for a |
| 88 |
few days. |
| 89 |
|
| 90 |
Here are the git-config(1) settings that control this behaviour: |
| 91 |
|
| 92 |
`lfs.pruneoffsetdays`:: |
| 93 |
The number of extra days added to the fetch recent settings when using |
| 94 |
them to decide when to prune. So for a reference to be considered old |
| 95 |
enough to prune, it has to be this many days older than the oldest |
| 96 |
reference that would be downloaded via `git lfs fetch --recent`. |
| 97 |
Only used if the relevant fetch recent 'days' setting is non-zero. |
| 98 |
Default 3 days. |
| 99 |
`lfs.fetchrecentrefsdays`:: |
| 100 |
`lfs.fetchrecentremoterefs`:: |
| 101 |
`lfs.fetchrecentcommitsdays`:: |
| 102 |
These have the same meaning as git-lfs-fetch(1) with the `--recent` |
| 103 |
option, they are used as a base for the offset above. Anything which |
| 104 |
falls outside of this offsetted window is considered old enough to |
| 105 |
prune. If a day value is zero, that condition is not used at all to |
| 106 |
retain objects and they will be pruned. |
| 107 |
|
| 108 |
== UNPUSHED LFS FILES |
| 109 |
|
| 110 |
When the only copy of an LFS file is local, and it is still reachable |
| 111 |
from any reference, that file can never be pruned, regardless of how old |
| 112 |
it is. |
| 113 |
|
| 114 |
To determine whether an LFS file has been pushed, we check the |
| 115 |
difference between local refs and remote refs; where the local ref is |
| 116 |
ahead, any LFS files referenced in those commits is unpushed and will |
| 117 |
not be deleted. This works because the LFS pre-push hook always ensures |
| 118 |
that LFS files are pushed before the remote branch is updated. |
| 119 |
|
| 120 |
See <<_default_remote>>, for which remote is considered 'pushed' for |
| 121 |
pruning purposes. |
| 122 |
|
| 123 |
== VERIFY REMOTE |
| 124 |
|
| 125 |
The `--verify-remote` option calls the remote to ensure that any reachable |
| 126 |
LFS files to be deleted have copies on the remote before actually deleting |
| 127 |
them. |
| 128 |
|
| 129 |
Usually the check performed by <<_unpushed_lfs_files>> is enough to |
| 130 |
determine that files have been pushed, but if you want to be extra sure |
| 131 |
at the expense of extra overhead you can make prune actually call the |
| 132 |
remote API and verify the presence of the files you're about to delete |
| 133 |
locally. See <<_default_remote>> for which remote is checked. |
| 134 |
|
| 135 |
You can make this behaviour the default by setting |
| 136 |
`lfs.pruneverifyremotealways` to true. |
| 137 |
|
| 138 |
In addition to the overhead of calling the remote, using this option |
| 139 |
also requires prune to distinguish between totally unreachable files |
| 140 |
(e.g. those that were added to the index but never committed, or |
| 141 |
referenced only by orphaned commits), and files which are still |
| 142 |
referenced, but by commits which are prunable. This makes the prune |
| 143 |
process take longer. |
| 144 |
|
| 145 |
If you want to verify unreachable objects as well, set the |
| 146 |
`--verify-unreachable` option. |
| 147 |
|
| 148 |
You can check for unreachable objects by default by setting |
| 149 |
`lfs.pruneverifyunreachablealways` to true. |
| 150 |
|
| 151 |
By default, `--verify-remote` halts execution if a file cannot be |
| 152 |
verified. Set `--when-unverified=continue` to not halt exceution but |
| 153 |
continue deleting all objects that can be verified. |
| 154 |
|
| 155 |
== DEFAULT REMOTE |
| 156 |
|
| 157 |
When identifying <<_unpushed_lfs_files>> and performing <<_verify_remote>>, a |
| 158 |
single remote, 'origin', is normally used as the reference. This one |
| 159 |
remote is considered canonical; even if you use multiple remotes, you |
| 160 |
probably want to retain your local copies until they've made it to that |
| 161 |
remote. 'origin' is used by default because that will usually be a main |
| 162 |
central repo, or your fork of it - in both cases that's a valid remote |
| 163 |
backup of your work. If origin doesn't exist then by default nothing |
| 164 |
will be pruned because everything is treated as 'unpushed'. |
| 165 |
|
| 166 |
You can alter the remote via git config: `lfs.pruneremotetocheck`. Set |
| 167 |
this to a different remote name to check that one instead of 'origin'. |
| 168 |
|
| 169 |
== SEE ALSO |
| 170 |
|
| 171 |
git-lfs-fetch(1), gitignore(5). |
| 172 |
|
| 173 |
Part of the git-lfs(1) suite. |