1GIT-LFS-MIGRATE(1)          General Commands Manual         GIT-LFS-MIGRATE(1)
2
3
4

NAME

6       git-lfs-migrate - Migrate history to or from Git LFS
7

SYNOPSIS

9       git lfs migrate mode [options] [--] [branch ...]
10

DESCRIPTION

12       Convert  files in a Git repository to or from Git LFS pointers, or sum‐
13       marize Git file sizes by file type. The import mode converts Git  files
14       (i.e.,  blobs)  to Git LFS, while the export mode does the reverse, and
15       the info mode provides an informational summary which may be useful  in
16       deciding which files to import or export.
17
18       In all modes, by default git lfs migrate operates only on the currently
19       checked-out branch, and only on files (of any size and type)  added  in
20       commits  which  do not exist on any remote. Multiple options are avail‐
21       able to override these defaults.
22
23       When converting files to or from Git LFS, the git lfs  migrate  command
24       will only make changes to your local repository and working copy, never
25       any remotes. This is intentional as the import  and  export  modes  are
26       generally  "destructive"  in  the sense that they rewrite your Git his‐
27       tory, changing commits and generating new commit SHAs.  (The  exception
28       is  the "no-rewrite" import sub-mode; see [IMPORT (NO REWRITE)] for de‐
29       tails.)
30
31       You should therefore always first commit or stash any uncommitted  work
32       before  using  the import or export modes, and then validate the result
33       of the migration before pushing the changes to your  remotes,  for  in‐
34       stance  by running the info mode and by examining your rewritten commit
35       history.
36
37       Once you are satisfied with the changes, you will  need  to  force-push
38       the new Git history of any rewritten branches to all your remotes. This
39       is a step which should be taken with care, since you will  be  altering
40       the Git history on your remotes.
41
42       To  examine  or  modify  files  in  branches  other  than the currently
43       checked-out one, branch refs may be specified directly, or provided  in
44       one or more --include-ref options. They may also be excluded by prefix‐
45       ing them with ^ or providing them in  --exclude-ref  options.  Use  the
46       --everything  option  to  specify that all refs should be examined, in‐
47       cluding all remote refs. See [INCLUDE AND EXCLUDE (REFS)] for details.
48
49       For the info and import modes, all file types  are  considered  by  de‐
50       fault;  while useful in the info mode, this is often not desirable when
51       importing, so either filename patterns (pathspecs) or the  --fixup  op‐
52       tion  should  normally be specified in that case. (At least one include
53       pathspec is required for the export mode.) Pathspecs may be defined us‐
54       ing  the  --include and --exclude options (-I and -X for short), as de‐
55       scribed in INCLUDE AND EXCLUDE.
56
57       As typical Git LFS usage depends on tracking specific file types  using
58       filename  patterns defined in .gitattributes files, the git lfs migrate
59       command will examine, create, and modify .gitattributes files as neces‐
60       sary.
61
62       The import mode (see IMPORT) will convert Git objects of the file types
63       specified (e.g., with --include) to Git LFS pointers, and will add  en‐
64       tries  for  those  file  types  to .gitattributes files, creating those
65       files if they do not exist. The result should be as if  git  lfs  track
66       commands  had  been run at the points in your Git history corresponding
67       to where each type of converted file first appears. The exception is if
68       the  --fixup  option  is given, in which case the import mode will only
69       examine any existing .gitattributes files and then convert Git  objects
70       which should be tracked by Git LFS but are not yet.
71
72       The  export mode (see EXPORT) works as the reverse operation to the im‐
73       port mode, converting any Git LFS pointers that match  the  file  types
74       specified  with --include, which must be given at least once. Note that
75       .gitattributes entries will not be removed, nor  will  the  files;  in‐
76       stead,  the export mode inserts "do not track" entries similar to those
77       created by the git lfs untrack command. The --remote option  is  avail‐
78       able  in  the  export mode to specify the remote from which Git LFS ob‐
79       jects should be fetched if they do not exist in the local Git  LFS  ob‐
80       ject cache; if not provided, origin is used by default.
81
82       The info mode (see INFO) summarizes by file type (i.e., by filename ex‐
83       tension) the total number and size of files in a repository. Note  that
84       like the other two modes, by default the info mode operates only on the
85       currently checked-out branch and only on commits which do not exist  on
86       any  remote,  so  to  get a summary of the entire repository across all
87       branches, use the --everything option. If  objects  have  already  been
88       converted  to  Git LFS pointers, then by default the size of the refer‐
89       enced objects is totaled and reported separately. You may  also  choose
90       to  ignore  them by using --pointers=ignore or to treat the pointers as
91       files by using --pointers=no-follow. (The latter option is akin to  how
92       existing  Git  LFS pointers were handled by the info mode in prior ver‐
93       sions of Git LFS).
94
95       When using the --everything option, take note that it  means  all  refs
96       (local  and  remote)  will  be considered, but not necessarily all file
97       types. The import and info modes consider all file  types  by  default,
98       although  the  --include and --exclude options constrain this behavior.
99       Also note that after importing across all branches  with  the  --every‐
100       thing  option  (and  then  checking to ensure the results are satisfac‐
101       tory!) it may be convenient to update multiple branches on your remotes
102       by using the --all option to git push.
103
104       Unless  the --skip-fetch option is given, git lfs migrate always begins
105       by fetching updated lists of refs from all the remotes returned by  git
106       remote, but as noted above, after making changes to your local Git his‐
107       tory while converting objects, it will never automatically  push  those
108       changes to your remotes.
109

MODES

111info Show information about repository size. See INFO.
112
113import Convert Git objects to Git LFS pointers. See IMPORT and [IM‐
114           PORT (NO REWRITE)].
115
116export Convert Git LFS pointers to Git objects. See EXPORT.
117
118
119

OPTIONS

121       -I paths --include=paths
122              See INCLUDE AND EXCLUDE.
123
124       -X paths --exclude=paths
125              See INCLUDE AND EXCLUDE.
126
127       --include-ref=refname
128              See [INCLUDE AND EXCLUDE (REFS)].
129
130       --exclude-ref=refname
131              See [INCLUDE AND EXCLUDE (REFS)].
132
133       --skip-fetch
134              Assumes that the known set of remote references is complete, and
135              should  not be refreshed when determining the set of "un-pushed"
136              commits to migrate. Has  no  effect  when  combined  with  --in‐
137              clude-ref or --exclude-ref.
138
139       --everything
140              See [INCLUDE AND EXCLUDE (REFS)].
141
142              Note:  Git refs are "case-sensitive" on all platforms in "packed
143              from" (see git-pack-refs(1)). On  "case-insensitive"  file  sys‐
144              tems, e.g. NTFS on Windows or default APFS on macOS, git-lfs-mi‐
145              grate(1) would only migrate the first ref if two  or  more  refs
146              are equal except for upper/lower case letters.
147
148       --yes  Assume  a  yes  answer to any prompts, permitting noninteractive
149              use. Currently, the only such prompt is the one  asking  whether
150              to  overwrite (destroy) any working copy changes. Thus, specify‐
151              ing this option may cause data loss if you are not careful.
152
153       [branch ...]
154              Migrate  only  the  set  of  branches  listed.  If  not   given,
155              git-lfs-migrate(1)   will  migrate  the  currently  checked  out
156              branch.
157
158              References beginning with ^ will be excluded,  whereas  branches
159              that do not begin with ^ will be included.
160
161              If  any of --include-ref or --exclude-ref are given, the checked
162              out branch will not be appended, but branches  given  explicitly
163              will be appended.
164
165   INFO
166       The  info  mode summarizes the sizes of file objects present in the Git
167       history. It supports all the core migrate options and these  additional
168       ones:
169
170--above=<size>  Only count files whose individual filesize is above
171           the given size. size may be specified as a number of  bytes,  or  a
172           number  followed  by  a storage unit, e.g., "1b", "20 MB", "3 TiB",
173           etc.
174
175           If a set of files sharing a common extension has no files  in  that
176           set  whose  individual  size is above the given --above no files no
177           entry for that set will be shown.
178
179--top=<n> Only display the top n entries, ordered by how many total
180           files match the given pathspec. The default is to show only the top
181           5 entries. When existing Git LFS objects are found, an extra, sepa‐
182           rate "LFS Objects" line is output in addition to the top n entries,
183           unless the --pointers option is used to change this behavior.
184
185--unit=<unit> Format the number of bytes in each entry as  a  quan‐
186           tity  of  the storage unit provided. Valid units include: * b, kib,
187           mib, gib, tib, pib - for IEC storage units * b, kb, mb, gb, tb,  pb
188           - for SI storage units
189
190           If  a  --unit  is  not specified, the largest unit that can fit the
191           number of counted bytes as a whole number quantity is chosen.
192
193--pointers=[follow|no-follow|ignore] Treat existing Git LFS  point‐
194           ers  in  the history according to one of three alternatives. In the
195           default follow case, if any pointers are found, an additional sepa‐
196           rate  "LFS  Objects" line item is output which summarizes the total
197           number and size of the Git LFS objects referenced by  pointers.  In
198           the ignore case, any pointers are simply ignored, while the no-fol‐
199           low case replicates the behavior of the info mode in older Git  LFS
200           versions  and  treats any pointers it finds as if they were regular
201           files, so the output totals only include the contents of the point‐
202           ers, not the contents of the objects to which they refer.
203
204--fixup Infer --include and --exclude filters on a per-commit basis
205           based on the .gitattributes files in  a  repository.  In  practice,
206           this option counts any filepaths which should be tracked by Git LFS
207           according to the repository´s .gitattributes  file(s),  but  aren´t
208           already  pointers.  The  .gitattributes  files are not reported, in
209           contrast to the normal output of the info mode. This option is  in‐
210           compatible  with  explicitly given --include, --exclude filters and
211           with any --pointers setting other than ignore,  hence  --fixup  im‐
212           plies --pointers=ignore if it is not explicitly set.
213
214
215
216       The  format of the output shows the filename pattern, the total size of
217       the file objects (excluding those below the --above threshold,  if  one
218       was  defined), and the ratio of the number of files above the threshold
219       to the total number of files; this ratio is also shown as a percentage.
220       For example:
221
222       *.gif      93  MB      9480/10504  files(s)   90%  *.png     14 MB
223       1732/1877 files(s)  92%
224
225       By default only the top five entries are shown, but  --top  allows  for
226       more or fewer to be output as desired.
227
228   IMPORT
229       The  import mode migrates objects present in the Git history to pointer
230       files tracked and stored with Git LFS. It supports all the core migrate
231       options and these additional ones:
232
233--verbose  Print  the  commit oid and filename of migrated files to
234           STDOUT.
235
236--above=<size> Only migrate  files  whose  individual  filesize  is
237           above  the  given size. size may be specified as a number of bytes,
238           or a number followed by a storage unit, e.g.,  "1b",  "20  MB",  "3
239           TiB", etc.
240
241--object-map=<path>  Write  to path a file with the mapping of each
242           rewritten commits. The  file  format  is  CSV  with  this  pattern:
243           OLD-SHA,NEW-SHA
244
245--no-rewrite  Migrate  objects  to  Git LFS in a new commit without
246           rewriting Git history. Please note that when this option  is  used,
247           the  migrate  import command will expect a different argument list,
248           specialized options will become available, and the core migrate op‐
249           tions will be ignored. See [IMPORT (NO REWRITE)].
250
251--fixup Infer --include and --exclude filters on a per-commit basis
252           based on the .gitattributes files in  a  repository.  In  practice,
253           this  option  imports  any filepaths which should be tracked by Git
254           LFS according  to  the  repository´s  .gitattributes  file(s),  but
255           aren´t  already  pointers. This option is incompatible with explic‐
256           itly given --include, --exclude filters.
257
258
259
260       If --no-rewrite is not provided and --include or --exclude (-I, -X, re‐
261       spectively)  are  given, the .gitattributes will be modified to include
262       any new filepath patterns as given by those flags.
263
264       If --no-rewrite is not provided and neither of those flags  are  given,
265       the  gitattributes  will  be  incrementally  modified  to  include  new
266       filepath extensions as they are rewritten in history.
267
268   IMPORT (NO REWRITE)
269       The import mode has a special  sub-mode  enabled  by  the  --no-rewrite
270       flag. This sub-mode will migrate objects to pointers as in the base im‐
271       port mode, but will do so in a new commit without  rewriting  Git  his‐
272       tory. When using this sub-mode, the base migrate options, such as --in‐
273       clude-ref, will be ignored, as will those for the base import mode. The
274       migrate  command  will also take a different argument list. As a result
275       of these changes, --no-rewrite will only operate on the current  branch
276       -  any  other interested branches must have the generated commit merged
277       in.
278
279       The --no-rewrite sub-mode supports the following options and arguments:
280
281-m <message> --message=<message> Specifies a commit message for the
282           newly created commit.
283
284       ○   [file ...] The list of files to import. These files must be tracked
285           by patterns specified in the gitattributes.
286
287
288
289       If --message is given, the new commit will be created with the provided
290       message.  If  no  message  is given, a commit message will be generated
291       based on the file arguments.
292
293   EXPORT
294       The export mode migrates Git LFS pointer files present in the Git  his‐
295       tory  out  of  Git LFS, converting them into their corresponding object
296       files. It supports all the core migrate options  and  these  additional
297       ones:
298
299--verbose  Print  the  commit oid and filename of migrated files to
300           STDOUT.
301
302--object-map=<path> Write to path a file with the mapping  of  each
303           rewritten  commit.  The  file  format  is  CSV  with  this pattern:
304           OLD-SHA,NEW-SHA
305
306--remote=<git-remote>  Download  LFS  objects  from  the   provided
307           git-remote during the export. If not provided, defaults to origin.
308
309
310
311       The  export  mode requires at minimum a pattern provided with the --in‐
312       clude argument to specify which files to  export.  Files  matching  the
313       --include  patterns  will be removed from Git LFS, while files matching
314       the --exclude patterns will retain their Git  LFS  status.  The  export
315       command  will  modify the .gitattributes to set/unset any filepath pat‐
316       terns as given by those flags.
317

INCLUDE AND EXCLUDE

319       You can specify that git lfs migrate should only  convert  files  whose
320       pathspec  matches  the  --include  glob patterns and does not match the
321       --exclude glob patterns, either to reduce total migration  time  or  to
322       only  migrate  part  of your repo. Multiple patterns may be given using
323       commas as delimiters.
324
325       Pattern matching is done so as to be  functionally  equivalent  to  the
326       pattern  matching  format of .gitattributes. In addition to simple file
327       extension matches (e.g., *.gif) patterns  may  also  specify  directory
328       paths,  in  which  case  the path/** format may be used to match recur‐
329       sively.
330

INCLUDE AND EXCLUDE (REFS)

332       You can specify that git lfs migrate should only convert files added in
333       commits  reachable  from certain references, namely those defined using
334       one or more --include-ref options, and should ignore files  in  commits
335       reachable from references defined in --exclude-ref options.
336
337       D---E---F  / \ A---B------C refs/heads/my-feature \ \ \ refs/heads/main
338       \ refs/remotes/origin/main
339
340       In the above configuration, the following commits are reachable by each
341       ref:
342
343       refs/heads/main:  C, B, A refs/heads/my-feature: F, E, D, B, A refs/re‐
344       mote/origin/main: A
345
346       The following git lfs migrate options would, therefore, include commits
347       F, E, D, C, and B, but exclude commit A:
348
349       --include-ref=refs/heads/my-feature --include-ref=refs/heads/main --ex‐
350       clude-ref=refs/remotes/origin/main
351
352       The presence of flag --everything indicates that all local  and  remote
353       references should be migrated.
354

EXAMPLES

356   Migrate unpushed commits
357       A  common  use case for the migrate command is to convert large Git ob‐
358       jects to LFS before pushing your commits. By  default,  it  only  scans
359       commits  that  don´t  exist on any remote, so long as the repository is
360       non-bare.
361
362       First, run git lfs migrate info to list the file types  taking  up  the
363       most space in your repository:
364
365       $  git  lfs  migrate  info migrate: Fetching remote refs: ..., done mi‐
366       grate: Sorting commits: ...,  done  migrate:  Examining  commits:  100%
367       (1/1),  done  *.mp3       284 MB     1/1 files(s)  100% *.pdf     42 MB
368            8/8  files(s)     100%  *.psd      9.8  MB    15/15  files(s) 100%
369       *.ipynb   6.9  MB       6/6  files(s)  100%  *.csv      5.8  MB     2/2
370       files(s)  100%
371
372       Now, you can run git lfs migrate import to convert some file  types  to
373       LFS:
374
375       $  git lfs migrate import --include="*.mp3,*.psd" migrate: Fetching re‐
376       mote refs: ..., done  migrate:  Sorting  commits:  ...,  done  migrate:
377       Rewriting          commits:          100%          (1/1),          done
378       main   d2b959babd099fe70da1c1512e2475e8a24de163                      ->
379       136e706bf1ae79643915c134e17a6c933fd53c61  migrate:  Updating refs: ...,
380       done
381
382       If after conversion you find that some files in your working  directory
383       have been replaced with Git LFS pointers, this is normal, and the work‐
384       ing copies of these files can be repopulated with their  full  expected
385       contents by using git lfs checkout.
386
387   Migrate local history
388       You can also migrate the entire history of your repository:
389
390       ```  # Check for large files and existing Git LFS objects in your local
391       main branch $ git lfs migrate info --include-ref=main$ git lfs  migrate
392       info  --everything#  and listing the top 100 or fewer results $ git lfs
393       migrate info --everything --pointers=ignore --top=100 ```
394
395       The same flags will work in import mode:
396
397       ``` # Convert all zip files in your main branch $ git lfs  migrate  im‐
398       port --include-ref=main --include="*.zip"$ git lfs migrate import --ev‐
399       erything  --include="*.zip"$  git  lfs  migrate   import   --everything
400       --above=100Kb ```
401
402       Note: This will require a force-push to any existing Git remotes. Using
403       the --all option when force-pushing may be convenient if many refs were
404       updated, e.g., after importing to Git LFS with the --everything option.
405
406   Migrate without rewriting local history
407       You  can  also  migrate files without modifying the existing history of
408       your repository. Note that in the examples below, files in  subdirecto‐
409       ries are not included because they are not explicitly specified.
410
411       Without a specified commit message:
412
413       $ git lfs migrate import --no-rewrite test.zip *.mp3 *.psd
414
415       With a specified commit message:
416
417       $ git lfs migrate import --no-rewrite \ -m "Import test.zip, .mp3, .psd
418       files in root of repo" \ test.zip *.mp3 *.psd
419

SEE ALSO

421       git-lfs-checkout(1),   git-lfs-track(1),   git-lfs-untrack(1),   gitat‐
422       tributes(5).
423
424       Part of the git-lfs(1) suite.
425
426
427
428                                 October 2021               GIT-LFS-MIGRATE(1)
Impressum