| 1 |
= git-lfs-migrate(1) |
| 2 |
|
| 3 |
== NAME |
| 4 |
|
| 5 |
git-lfs-migrate - Migrate history to or from Git LFS |
| 6 |
|
| 7 |
== SYNOPSIS |
| 8 |
|
| 9 |
[source,role=synopsis,subs="verbatim,quotes"] |
| 10 |
---- |
| 11 |
*git lfs migrate* _<mode>_ [_options_] [*--*] [_branch_ ...] |
| 12 |
---- |
| 13 |
|
| 14 |
== DESCRIPTION |
| 15 |
|
| 16 |
Convert files in a Git repository to or from Git LFS pointers, or |
| 17 |
summarize Git file sizes by file type. The `import` mode converts Git |
| 18 |
files (i.e., blobs) to Git LFS, while the `export` mode does the |
| 19 |
reverse, and the `info` mode provides an informational summary which may |
| 20 |
be useful in deciding which files to import or export. |
| 21 |
|
| 22 |
In all modes, by default `git lfs migrate` operates only on the |
| 23 |
currently checked-out branch, and only on files (of any size and type) |
| 24 |
added in commits which do not exist on any remote. Multiple options are |
| 25 |
available to override these defaults. |
| 26 |
|
| 27 |
When converting files to or from Git LFS, the `git lfs migrate` command |
| 28 |
will only make changes to your local repository and working copy, never |
| 29 |
any remotes. This is intentional as the `import` and `export` modes are |
| 30 |
generally "destructive" in the sense that they rewrite your Git history, |
| 31 |
changing commits and generating new commit SHAs. (The exception is the |
| 32 |
"no-rewrite" `import` sub-mode; see <<_import_without_rewriting_history>> |
| 33 |
for details.) |
| 34 |
|
| 35 |
You should therefore always first commit or stash any uncommitted work |
| 36 |
before using the `import` or `export` modes, and then validate the |
| 37 |
result of the migration before pushing the changes to your remotes, for |
| 38 |
instance by running the `info` mode and by examining your rewritten |
| 39 |
commit history. |
| 40 |
|
| 41 |
Once you are satisfied with the changes, you will need to force-push the |
| 42 |
new Git history of any rewritten branches to all your remotes. This is a |
| 43 |
step which should be taken with care, since you will be altering the Git |
| 44 |
history on your remotes. |
| 45 |
|
| 46 |
To examine or modify files in branches other than the currently |
| 47 |
checked-out one, branch refs may be specified directly, or provided in |
| 48 |
one or more `--include-ref` options. They may also be excluded by |
| 49 |
prefixing them with `^` or providing them in `--exclude-ref` options. |
| 50 |
Use the `--everything` option to specify that all refs should be |
| 51 |
examined, including all remote refs. See <<_include_and_exclude_references>> |
| 52 |
for details. |
| 53 |
|
| 54 |
For the `info` and `import` modes, all file types are considered by |
| 55 |
default; while useful in the `info` mode, this is often not desirable |
| 56 |
when importing, so either filename patterns (pathspecs) or the `--fixup` |
| 57 |
option should normally be specified in that case. (At least one include |
| 58 |
pathspec is required for the `export` mode.) Pathspecs may be defined |
| 59 |
using the `--include` and `--exclude` options (`-I` and `-X` for short), |
| 60 |
as described in <<_include_and_exclude>>. |
| 61 |
|
| 62 |
As typical Git LFS usage depends on tracking specific file types using |
| 63 |
filename patterns defined in `.gitattributes` files, the |
| 64 |
`git lfs migrate` command will examine, create, and modify |
| 65 |
`.gitattributes` files as necessary. The `.gitattributes` files will |
| 66 |
always be assigned the default read/write permissions mode (i.e., |
| 67 |
without execute permissions). Any symbolic links with that name will |
| 68 |
cause the migration to halt prematurely. |
| 69 |
|
| 70 |
The `import` mode (see <<_import>>) will convert Git objects of the file |
| 71 |
types specified (e.g., with `--include`) to Git LFS pointers, and will |
| 72 |
add entries for those file types to `.gitattributes` files, creating |
| 73 |
those files if they do not exist. The result should be as if |
| 74 |
`git lfs track` commands had been run at the points in your Git history |
| 75 |
corresponding to where each type of converted file first appears. The |
| 76 |
exception is if the `--fixup` option is given, in which case the |
| 77 |
`import` mode will only examine any existing `.gitattributes` files and |
| 78 |
then convert Git objects which should be tracked by Git LFS but are not |
| 79 |
yet. |
| 80 |
|
| 81 |
The `export` mode (see <<_export>>) works as the reverse operation to the |
| 82 |
`import` mode, converting any Git LFS pointers that match the file types |
| 83 |
specified with `--include`, which must be given at least once. Note that |
| 84 |
`.gitattributes` entries will not be removed, nor will the files; |
| 85 |
instead, the `export` mode inserts "do not track" entries similar to |
| 86 |
those created by the `git lfs untrack` command. The `--remote` option is |
| 87 |
available in the `export` mode to specify the remote from which Git LFS |
| 88 |
objects should be fetched if they do not exist in the local Git LFS |
| 89 |
object cache; if not provided, `origin` is used by default. |
| 90 |
|
| 91 |
The `info` mode (see <<_info>>) summarizes by file type (i.e., by filename |
| 92 |
extension) the total number and size of files in a repository. Note that |
| 93 |
like the other two modes, by default the `info` mode operates only on |
| 94 |
the currently checked-out branch and only on commits which do not exist |
| 95 |
on any remote, so to get a summary of the entire repository across all |
| 96 |
branches, use the `--everything` option. If objects have already been |
| 97 |
converted to Git LFS pointers, then by default the size of the |
| 98 |
referenced objects is totaled and reported separately. You may also |
| 99 |
choose to ignore them by using `--pointers=ignore` or to treat the |
| 100 |
pointers as files by using `--pointers=no-follow`. (The latter option is |
| 101 |
akin to how existing Git LFS pointers were handled by the `info` mode in |
| 102 |
prior versions of Git LFS). |
| 103 |
|
| 104 |
When using the `--everything` option, take note that it means all commits |
| 105 |
reachable from all refs (local and remote) will be considered, but not |
| 106 |
necessarily all file types. The `import` and `info` modes consider all file |
| 107 |
types by default, although the `--include` and `--exclude` options constrain |
| 108 |
this behavior. |
| 109 |
|
| 110 |
While the `--everything` option means all commits reachable from any |
| 111 |
ref will be considered for migration, after migration only local refs will |
| 112 |
be updated even when `--everything` is specified. This ensures remote |
| 113 |
refs stay synchronized with their remote. In other words, `refs/heads/foo` |
| 114 |
will be updated with the `--everything` option, but `refs/remotes/origin/foo` |
| 115 |
will not, so it stays in sync with the remote until `git push origin foo` |
| 116 |
is performed. After checking that the results of a migration with |
| 117 |
`--everything` are satisfactory, it may be convenient to push all local |
| 118 |
branches to your remotes by using the `--all` option to `git push`. |
| 119 |
|
| 120 |
Unless the `--skip-fetch` option is given, `git lfs migrate` always |
| 121 |
begins by fetching updated lists of refs from all the remotes returned |
| 122 |
by `git remote`, but as noted above, after making changes to your local |
| 123 |
Git history while converting objects, it will never automatically push |
| 124 |
those changes to your remotes. |
| 125 |
|
| 126 |
== MODES |
| 127 |
|
| 128 |
info:: |
| 129 |
Show information about repository size. See <<_info>>. |
| 130 |
import:: |
| 131 |
Convert Git objects to Git LFS pointers. See <<_import>> and |
| 132 |
<<_import_without_rewriting_history>> |
| 133 |
export:: |
| 134 |
Convert Git LFS pointers to Git objects. See <<_export>>. |
| 135 |
|
| 136 |
== OPTIONS |
| 137 |
|
| 138 |
`-I <paths>`:: |
| 139 |
`--include=<paths>`:: |
| 140 |
See <<_include_and_exclude>>. |
| 141 |
`-X <paths>`:: |
| 142 |
`--exclude=<paths>`:: |
| 143 |
See <<_include_and_exclude>>. |
| 144 |
`--include-ref=<refname>`:: |
| 145 |
See <<_include_and_exclude_references>>. |
| 146 |
`--exclude-ref=<refname>`:: |
| 147 |
See <<_include_and_exclude_references>>. |
| 148 |
`--skip-fetch`:: |
| 149 |
Assumes that the known set of remote references is complete, and should not be |
| 150 |
refreshed when determining the set of "un-pushed" commits to migrate. Has no |
| 151 |
effect when combined with `--include-ref` or `--exclude-ref`. |
| 152 |
`--everything`:: |
| 153 |
See <<_include_and_exclude_references>>. |
| 154 |
+ |
| 155 |
Note: Git refs are "case-sensitive" on all platforms in "packed from" |
| 156 |
(see `git-pack-refs(1)`). On "case-insensitive" file systems, e.g. NTFS |
| 157 |
on Windows or default APFS on macOS, `git-lfs-migrate(1)` would only |
| 158 |
migrate the first ref if two or more refs are equal except for |
| 159 |
upper/lower case letters. |
| 160 |
`--yes`:: |
| 161 |
Assume a yes answer to any prompts, permitting noninteractive use. Currently, |
| 162 |
the only such prompt is the one asking whether to overwrite (destroy) any |
| 163 |
working copy changes. Thus, specifying this option may cause data loss if you |
| 164 |
are not careful. |
| 165 |
`[branch ...]`:: |
| 166 |
Migrate only the set of branches listed. If not given, `git-lfs-migrate(1)` |
| 167 |
will migrate the currently checked out branch. |
| 168 |
+ |
| 169 |
References beginning with `^` will be excluded, whereas branches that do |
| 170 |
not begin with `^` will be included. |
| 171 |
+ |
| 172 |
If any of `--include-ref` or `--exclude-ref` are given, the checked out |
| 173 |
branch will not be appended, but branches given explicitly will be |
| 174 |
appended. |
| 175 |
|
| 176 |
=== INFO |
| 177 |
|
| 178 |
The `info` mode summarizes the sizes of file objects present in the Git |
| 179 |
history. It supports all the core `migrate` options and these additional |
| 180 |
ones: |
| 181 |
|
| 182 |
`--above=<size>`:: |
| 183 |
Only count files whose individual filesize is above the given size. `size` may |
| 184 |
be specified as a number of bytes, or a number followed by a storage unit, |
| 185 |
e.g., "1b", "20 MB", "3 TiB", etc. |
| 186 |
+ |
| 187 |
If a set of files sharing a common extension has no files in that set |
| 188 |
whose individual size is above the given `--above` no files no entry for |
| 189 |
that set will be shown. |
| 190 |
`--top=<n>`:: |
| 191 |
Only display the top `n` entries, ordered by how many total files match the |
| 192 |
given pathspec. The default is to show only the top 5 entries. When existing |
| 193 |
Git LFS objects are found, an extra, separate "LFS Objects" line is output in |
| 194 |
addition to the top `n` entries, unless the `--pointers` option is used to |
| 195 |
change this behavior. |
| 196 |
`--unit=<unit>`:: |
| 197 |
Format the number of bytes in each entry as a quantity of the storage unit |
| 198 |
provided. Valid units include: |
| 199 |
** b, kib, mib, gib, tib, pib - for IEC storage units |
| 200 |
** b, kb, mb, gb, tb, pb - for SI storage units |
| 201 |
+ |
| 202 |
If a `--unit` is not specified, the largest unit that can fit the number |
| 203 |
of counted bytes as a whole number quantity is chosen. |
| 204 |
`--pointers=[follow|no-follow|ignore]`:: |
| 205 |
Treat existing Git LFS pointers in the history according to one of three |
| 206 |
alternatives. In the default `follow` case, if any pointers are found, an |
| 207 |
additional separate "LFS Objects" line item is output which summarizes the |
| 208 |
total number and size of the Git LFS objects referenced by pointers. In the |
| 209 |
`ignore` case, any pointers are simply ignored, while the `no-follow` case |
| 210 |
replicates the behavior of the `info` mode in older Git LFS versions and |
| 211 |
treats any pointers it finds as if they were regular files, so the output |
| 212 |
totals only include the contents of the pointers, not the contents of the |
| 213 |
objects to which they refer. |
| 214 |
`--fixup`:: |
| 215 |
Infer `--include` and `--exclude` filters on a per-commit basis based on the |
| 216 |
`.gitattributes` files in a repository. In practice, this option counts any |
| 217 |
filepaths which should be tracked by Git LFS according to the repository's |
| 218 |
`.gitattributes` file(s), but aren't already pointers. The `.gitattributes` |
| 219 |
files are not reported, in contrast to the normal output of the `info` mode. |
| 220 |
This option is incompatible with explicitly given `--include`, `--exclude` |
| 221 |
filters and with any `--pointers` setting other than `ignore`, hence `--fixup` |
| 222 |
implies `--pointers=ignore` if it is not explicitly set. |
| 223 |
|
| 224 |
The format of the output shows the filename pattern, the total size of |
| 225 |
the file objects (excluding those below the `--above` threshold, if one |
| 226 |
was defined), and the ratio of the number of files above the threshold |
| 227 |
to the total number of files; this ratio is also shown as a percentage. |
| 228 |
For example: |
| 229 |
|
| 230 |
.... |
| 231 |
*.gif 93 MB 9480/10504 files(s) 90% |
| 232 |
*.png 14 MB 1732/1877 files(s) 92% |
| 233 |
.... |
| 234 |
|
| 235 |
By default only the top five entries are shown, but `--top` allows for |
| 236 |
more or fewer to be output as desired. |
| 237 |
|
| 238 |
=== IMPORT |
| 239 |
|
| 240 |
The `import` mode migrates objects present in the Git history to pointer |
| 241 |
files tracked and stored with Git LFS. It supports all the core |
| 242 |
`migrate` options and these additional ones: |
| 243 |
|
| 244 |
`--verbose`:: |
| 245 |
Print the commit oid and filename of migrated files to STDOUT. |
| 246 |
`--above=<size>`:: |
| 247 |
Only migrate files whose individual filesize is above the given size. `size` |
| 248 |
may be specified as a number of bytes, or a number followed by a storage unit, |
| 249 |
e.g., "1b", "20 MB", "3 TiB", etc. This option cannot be used with the |
| 250 |
`--include`, `--exclude`, and `--fixup` options. |
| 251 |
`--object-map=<path>`:: |
| 252 |
Write to `path` a file with the mapping of each rewritten commits. The file |
| 253 |
format is CSV with this pattern: `OLD-SHA`,`NEW-SHA` |
| 254 |
`--no-rewrite`:: |
| 255 |
Migrate objects to Git LFS in a new commit without rewriting Git history. |
| 256 |
Please note that when this option is used, the `migrate import` command will |
| 257 |
expect a different argument list, specialized options will become available, |
| 258 |
and the core `migrate` options will be ignored. |
| 259 |
See <<_import_without_rewriting_history>>. |
| 260 |
`--fixup`:: |
| 261 |
Infer `--include` and `--exclude` filters on a per-commit basis based on the |
| 262 |
`.gitattributes` files in a repository. In practice, this option imports any |
| 263 |
filepaths which should be tracked by Git LFS according to the repository's |
| 264 |
`.gitattributes` file(s), but aren't already pointers. This option is |
| 265 |
incompatible with explicitly given `--include`, `--exclude` filters. |
| 266 |
|
| 267 |
If `--no-rewrite` is not provided and `--include` or `--exclude` (`-I`, |
| 268 |
`-X`, respectively) are given, the `.gitattributes` will be modified to |
| 269 |
include any new filepath patterns as given by those flags. |
| 270 |
|
| 271 |
If `--no-rewrite` is not provided and neither of those flags are given, |
| 272 |
the gitattributes will be incrementally modified to include new filepath |
| 273 |
extensions as they are rewritten in history. |
| 274 |
|
| 275 |
=== IMPORT WITHOUT REWRITING HISTORY |
| 276 |
|
| 277 |
The `import` mode has a special sub-mode enabled by the `--no-rewrite` |
| 278 |
flag. This sub-mode will migrate objects to pointers as in the base |
| 279 |
`import` mode, but will do so in a new commit without rewriting Git |
| 280 |
history. When using this sub-mode, the base `migrate` options, such as |
| 281 |
`--include-ref`, will be ignored, as will those for the base `import` |
| 282 |
mode. The `migrate` command will also take a different argument list. As |
| 283 |
a result of these changes, `--no-rewrite` will only operate on the |
| 284 |
current branch - any other interested branches must have the generated |
| 285 |
commit merged in. |
| 286 |
|
| 287 |
The `--no-rewrite` sub-mode supports the following options and |
| 288 |
arguments: |
| 289 |
|
| 290 |
`-m <message>`:: |
| 291 |
`--message=<message>`:: |
| 292 |
Specifies a commit message for the newly created commit. |
| 293 |
[file ...]:: |
| 294 |
The list of files to import. These files must be tracked by |
| 295 |
patterns specified in the gitattributes. |
| 296 |
|
| 297 |
If `--message` is given, the new commit will be created with the |
| 298 |
provided message. If no message is given, a commit message will be |
| 299 |
generated based on the file arguments. |
| 300 |
|
| 301 |
=== EXPORT |
| 302 |
|
| 303 |
The `export` mode migrates Git LFS pointer files present in the Git |
| 304 |
history out of Git LFS, converting them into their corresponding object |
| 305 |
files. It supports all the core `migrate` options and these additional |
| 306 |
ones: |
| 307 |
|
| 308 |
`--verbose`:: |
| 309 |
Print the commit oid and filename of migrated files to |
| 310 |
STDOUT. |
| 311 |
`--object-map=<path>`:: |
| 312 |
Write to `path` a file with the mapping of each rewritten commit. The file |
| 313 |
format is CSV with this pattern: `OLD-SHA`,`NEW-SHA` |
| 314 |
`--remote=<git-remote>`:: |
| 315 |
Download LFS objects from the provided `git-remote` during the export. If not |
| 316 |
provided, defaults to `origin`. |
| 317 |
|
| 318 |
The `export` mode requires at minimum a pattern provided with the |
| 319 |
`--include` argument to specify which files to export. Files matching |
| 320 |
the `--include` patterns will be removed from Git LFS, while files |
| 321 |
matching the `--exclude` patterns will retain their Git LFS status. The |
| 322 |
export command will modify the `.gitattributes` to set/unset any |
| 323 |
filepath patterns as given by those flags. |
| 324 |
|
| 325 |
== INCLUDE AND EXCLUDE |
| 326 |
|
| 327 |
You can specify that `git lfs migrate` should only convert files whose |
| 328 |
pathspec matches the `--include` glob patterns and does not match the |
| 329 |
`--exclude` glob patterns, either to reduce total migration time or to |
| 330 |
only migrate part of your repo. Multiple patterns may be given using |
| 331 |
commas as delimiters. |
| 332 |
|
| 333 |
Pattern matching is done so as to be functionally equivalent to the |
| 334 |
pattern matching format of `.gitattributes`. In addition to simple file |
| 335 |
extension matches (e.g., `*.gif`) patterns may also specify directory |
| 336 |
paths, in which case the `path/**` format may be used to match |
| 337 |
recursively. |
| 338 |
|
| 339 |
Note that this form of pattern matching for the `--include` and |
| 340 |
`--exclude` options used by the `git lfs migrate` command is unique |
| 341 |
among the suite of `git lfs` commands. Other commands which also take |
| 342 |
these options, such as `git lfs ls-files`, use the gitignore(5) form of |
| 343 |
pattern matching instead. |
| 344 |
|
| 345 |
== INCLUDE AND EXCLUDE REFERENCES |
| 346 |
|
| 347 |
You can specify that `git lfs migrate` should only convert files added |
| 348 |
in commits reachable from certain references, namely those defined using |
| 349 |
one or more `--include-ref` options, and should ignore files in commits |
| 350 |
reachable from references defined in `--exclude-ref` options. |
| 351 |
|
| 352 |
.... |
| 353 |
D---E---F |
| 354 |
/ \ |
| 355 |
A---B------C refs/heads/my-feature |
| 356 |
\ \ |
| 357 |
\ refs/heads/main |
| 358 |
\ |
| 359 |
refs/remotes/origin/main |
| 360 |
.... |
| 361 |
|
| 362 |
In the above configuration, the following commits are reachable by each |
| 363 |
ref: |
| 364 |
|
| 365 |
.... |
| 366 |
refs/heads/main: C, B, A |
| 367 |
refs/heads/my-feature: F, E, D, B, A |
| 368 |
refs/remote/origin/main: A |
| 369 |
.... |
| 370 |
|
| 371 |
The following `git lfs migrate` options would, therefore, include |
| 372 |
commits F, E, D, C, and B, but exclude commit A: |
| 373 |
|
| 374 |
.... |
| 375 |
--include-ref=refs/heads/my-feature |
| 376 |
--include-ref=refs/heads/main |
| 377 |
--exclude-ref=refs/remotes/origin/main |
| 378 |
.... |
| 379 |
|
| 380 |
The presence of flag `--everything` indicates that all commits reachable |
| 381 |
from all local and remote references should be migrated (but note that |
| 382 |
the remote refs themselves will not be updated). |
| 383 |
|
| 384 |
== EXAMPLES |
| 385 |
|
| 386 |
=== Migrate unpushed commits |
| 387 |
|
| 388 |
A common use case for the migrate command is to convert large Git |
| 389 |
objects to LFS before pushing your commits. By default, it only scans |
| 390 |
commits that don't exist on any remote, so long as the repository is |
| 391 |
non-bare. |
| 392 |
|
| 393 |
First, run `git lfs migrate info` to list the file types taking up the |
| 394 |
most space in your repository: |
| 395 |
|
| 396 |
.... |
| 397 |
$ git lfs migrate info |
| 398 |
Fetching remote refs: ..., done |
| 399 |
Sorting commits: ..., done |
| 400 |
Examining commits: 100% (1/1), done |
| 401 |
*.mp3 284 MB 1/1 files(s) 100% |
| 402 |
*.pdf 42 MB 8/8 files(s) 100% |
| 403 |
*.psd 9.8 MB 15/15 files(s) 100% |
| 404 |
*.ipynb 6.9 MB 6/6 files(s) 100% |
| 405 |
*.csv 5.8 MB 2/2 files(s) 100% |
| 406 |
.... |
| 407 |
|
| 408 |
Now, you can run `git lfs migrate import` to convert some file types to |
| 409 |
LFS: |
| 410 |
|
| 411 |
.... |
| 412 |
$ git lfs migrate import --include="*.mp3,*.psd" |
| 413 |
Fetching remote refs: ..., done |
| 414 |
Sorting commits: ..., done |
| 415 |
Rewriting commits: 100% (1/1), done |
| 416 |
main d2b959babd099fe70da1c1512e2475e8a24de163 -> 136e706bf1ae79643915c134e17a6c933fd53c61 |
| 417 |
Updating refs: ..., done |
| 418 |
.... |
| 419 |
|
| 420 |
If after conversion you find that some files in your working directory |
| 421 |
have been replaced with Git LFS pointers, this is normal, and the |
| 422 |
working copies of these files can be repopulated with their full |
| 423 |
expected contents by using `git lfs checkout`. |
| 424 |
|
| 425 |
=== Migrate local history |
| 426 |
|
| 427 |
You can also migrate the entire history of your repository: |
| 428 |
|
| 429 |
.... |
| 430 |
# Check for large files and existing Git LFS objects in your local main branch |
| 431 |
$ git lfs migrate info --include-ref=main |
| 432 |
|
| 433 |
# Check for large files and existing Git LFS objects in every branch |
| 434 |
$ git lfs migrate info --everything |
| 435 |
|
| 436 |
# Check for large files in every branch, ignoring any existing Git LFS objects, |
| 437 |
# and listing the top 100 or fewer results |
| 438 |
$ git lfs migrate info --everything --pointers=ignore --top=100 |
| 439 |
.... |
| 440 |
|
| 441 |
The same flags will work in `import` mode: |
| 442 |
|
| 443 |
.... |
| 444 |
# Convert all zip files in your main branch |
| 445 |
$ git lfs migrate import --include-ref=main --include="*.zip" |
| 446 |
|
| 447 |
# Convert all zip files in every local branch |
| 448 |
$ git lfs migrate import --everything --include="*.zip" |
| 449 |
|
| 450 |
# Convert all files over 100K in every local branch |
| 451 |
$ git lfs migrate import --everything --above=100Kb |
| 452 |
.... |
| 453 |
|
| 454 |
Note: This will require a force-push to any existing Git remotes. Using |
| 455 |
the `--all` option when force-pushing may be convenient if many local refs |
| 456 |
were updated, e.g., after importing to Git LFS with the `--everything` |
| 457 |
option. |
| 458 |
|
| 459 |
=== Migrate without rewriting local history (using migrate import --no-rewrite) |
| 460 |
|
| 461 |
You can also migrate files without modifying the existing history of |
| 462 |
your repository. |
| 463 |
|
| 464 |
Migrating to Git LFS in a single new commit, without specifying a commit message: |
| 465 |
|
| 466 |
.... |
| 467 |
$ git lfs track "*.zip" "*.mp3" "*.psd" |
| 468 |
$ git add .gitattributes |
| 469 |
$ git commit -m "add Git LFS attributes" |
| 470 |
|
| 471 |
$ git lfs migrate import --no-rewrite --yes test.zip audios/*.mp3 images/*.psd |
| 472 |
.... |
| 473 |
|
| 474 |
Note that the `*.mp3` and `*.psd` filename patterns are not quoted and |
| 475 |
so will be expanded by the shell, not by the `git lfs migrate import` |
| 476 |
command. See the remarks following the next example for further details. |
| 477 |
|
| 478 |
Migrating to Git LFS in a single new commit, with a specified commit message: |
| 479 |
|
| 480 |
.... |
| 481 |
$ git lfs track "*.zip" "*.mp3" "*.psd" |
| 482 |
$ git add .gitattributes |
| 483 |
$ git commit -m "add Git LFS attributes" |
| 484 |
|
| 485 |
$ git lfs migrate import --no-rewrite --yes \ |
| 486 |
-m "Import test.zip, audios/*.mp3, and images/*.psd files" \ |
| 487 |
test.zip audios/*.mp3 images/*.psd |
| 488 |
.... |
| 489 |
|
| 490 |
Note that the `*.mp3` and `*.psd` filename patterns are not quoted and |
| 491 |
so will be expanded by the shell, not by the `git lfs migrate import` |
| 492 |
command. Using quotation marks around such patterns with the |
| 493 |
`--no-rewrite` option is not supported, as the command expects a list |
| 494 |
of files (possibly as expanded by the shell) and will not search for |
| 495 |
all files matching a quoted filename pattern. |
| 496 |
|
| 497 |
Additional commands may be used to find and list all files matching a set |
| 498 |
of patterns, of course. In a POSIX-compliant environment such as Linux, |
| 499 |
macOS, or Git Bash on Windows, the example above could be combined with |
| 500 |
the `find(1)` and `sed(1)` commands as follows, so long as the resulting |
| 501 |
list of files does not cause the length of the expanded command line to |
| 502 |
exceed the maximum permitted by the shell: |
| 503 |
|
| 504 |
.... |
| 505 |
$ git lfs migrate import --no-rewrite --yes \ |
| 506 |
$(find . -name "*.zip" -o -name "*.mp3" -o -name "*.psd" | sed "s/^\.\///") |
| 507 |
.... |
| 508 |
|
| 509 |
Note also that the `git lfs track` command will by default change the |
| 510 |
modification timestamps on any existing files which match the given |
| 511 |
filename patterns so the files will appear "dirty" to Git and thereby |
| 512 |
prompt the user to convert them to Git LFS files. The subsequent |
| 513 |
`git lfs migrate import` command will then caution that the working tree |
| 514 |
contains modifications and ask the user for confirmation to proceed |
| 515 |
unless the `--yes` option is specified, as in the examples above. |
| 516 |
|
| 517 |
=== Migrate without rewriting local history (using add --renormalize) |
| 518 |
|
| 519 |
As an alternative to using `git lfs migrate import` with the `--no-rewrite` |
| 520 |
option to migrate files to Git LFS without modifying the existing history |
| 521 |
of your repository, if you have Git v2.16.0 or higher installed, you can |
| 522 |
use the `--renormalize` option of the `git add` command to achieve |
| 523 |
the same result. For example: |
| 524 |
|
| 525 |
.... |
| 526 |
$ git lfs track "*.zip" "*.mp3" "*.psd" |
| 527 |
$ git add .gitattributes |
| 528 |
$ git add --renormalize . |
| 529 |
$ git commit -m "Import all *.zip, *.mp3, and *.psd files to Git LFS" |
| 530 |
.... |
| 531 |
|
| 532 |
=== Migrate from Git LFS |
| 533 |
|
| 534 |
If you no longer wish to use Git LFS for some or all of your files, you can |
| 535 |
use the `export` mode to convert Git LFS objects into regular Git blobs again. |
| 536 |
|
| 537 |
The `export` mode requires at least one `--include` pathspec, and will |
| 538 |
download any objects not found locally from your `origin` Git remote, or |
| 539 |
from the Git remote you specify with the `--remote` option. |
| 540 |
|
| 541 |
.... |
| 542 |
# Convert all zip Git LFS objects to files in your main branch |
| 543 |
$ git lfs migrate export --include-ref=main --include="*.zip" |
| 544 |
|
| 545 |
# Convert all zip Git LFS objects to files in every local branch, |
| 546 |
# fetching any object data not cached locally from the my-remote Git remote |
| 547 |
$ git lfs migrate export --everything --include="*.zip" --remote=my-remote |
| 548 |
|
| 549 |
# Convert all Git LFS objects to files in every local branch |
| 550 |
$ git lfs migrate export --everything --include="*" |
| 551 |
.... |
| 552 |
|
| 553 |
Note: This will require a force-push to any existing Git remotes. Using |
| 554 |
the `--all` option when force-pushing may be convenient if many local refs |
| 555 |
were updated, e.g., after exporting from Git LFS with the `--everything` |
| 556 |
option. |
| 557 |
|
| 558 |
== SEE ALSO |
| 559 |
|
| 560 |
git-lfs-checkout(1), git-lfs-ls-files(1), git-lfs-track(1), |
| 561 |
git-lfs-untrack(1), gitattributes(5), gitignore(5). |
| 562 |
|
| 563 |
Part of the git-lfs(1) suite. |