Christoph
Christoph

Reputation: 7063

Why does git lfs migrate not track all pdf files?

Note in advance: git lfs migrate import --include="*.pdf" does the job as git lfs ls-files shows e6521dbea0 - large180m.pdf (I guess). But I still don't understand what happens.


I need to use git lfs and I created a test folder in C:/Temp/ (on windows) to check whether everything is working. Unfortunatelly, it is not: git lfs ls-files does not list any files! See below...

(small.txt and small2.txt are empty text files, large180m.pdf is a "large" pdf with 180 MB)

What is wrong here? I followed the instructions from here:

SQC@N6812 MINGW64 /c/Temp
$ ls C:/Temp/*.pdf
C:/Temp/large180m.pdf

SQC@N6812 MINGW64 /c/Temp
$ git init
Initialized empty Git repository in C:/Temp/.git/

SQC@N6812 MINGW64 /c/Temp (master)
$ git add .

SQC@N6812 MINGW64 /c/Temp (master)
$ git commit -m "Initial commit including large file"
[master (root-commit) 035a6ca] Initial commit including large file
 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 large180m.pdf
 create mode 100644 small.txt
 create mode 100644 small2.txt

SQC@N6812 MINGW64 /c/Temp (master)
$ git status
On branch master
nothing to commit, working tree clean

SQC@N6812 MINGW64 /c/Temp (master)
$ git lfs migrate import --include="C:/Temp/*.pdf"
migrate: Fetching remote refs: ..., done
migrate: Sorting commits: ..., done
migrate: Rewriting commits: 100% (1/1), done
  master        035a6ca083c3300bf33b5e399a547e8141daeb05 -> 53861996e1fe34a82e9b4e1f7b951266b250c4de
migrate: Updating refs: ..., done
migrate: checkout: ..., done

SQC@N6812 MINGW64 /c/Temp (master)
$ git reflog expire --expire-unreachable=now --all

SQC@N6812 MINGW64 /c/Temp (master)
$ git gc --prune=now
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), done.
Total 5 (delta 0), reused 0 (delta 0)

SQC@N6812 MINGW64 /c/Temp (master)
$ git lfs track
Listing tracked patterns
    C:\Temp\*.pdf (.gitattributes)

SQC@N6812 MINGW64 /c/Temp (master)
$ git lfs ls-files

Note: Finally, the lfs should track pdf in all subfolders

From git lfs env:

git-lfs/2.3.4 (GitHub; windows amd64; go 1.8.3; git d2f6752f)
git version 2.16.2.windows.1

LocalWorkingDir=C:\Temp
LocalGitDir=C:\Temp\.git

Upvotes: 1

Views: 1774

Answers (2)

studog
studog

Reputation: 1088

@bk2204's answer says "Your problem is the path you gave to git lfs migrate import. The path you provide needs to be suitable for a .gitattributes file, which means it must be specified in relation to the root of your repository."

That cannot be overstated. Using Git for Windows 2.28.0 I was trying a command like

find . -path ./.git -prune -false -o -size +49M -print0 | xargs -r0t -n1 -I{} git lfs migrate import --everything --verbose --include "{}"

to add all files large enough for Github to complain about to LFS. The command ran and appeared to succeed, history was rewritten, .gitattributes was updated, etc. In fact, .gitattributes was updated correctly.

What wasn't working was the large files weren't being moved into LFS. The problem turned out to be find's output of ./foo/bar/mega.csv for a path. The git lfs command accepted that, stripped the leading ./ before updating .gitattributes but actually didn't move the file into LFS. Changing to

find . -path ./.git -prune -false -o -size +49M -printf '%P\0' | xargs -r0t -n1 -I{} git lfs migrate import --everything --verbose --include "{}"

made it work.

Posting in the hopes that I save someone else (perhaps future-me) some time and frustration.

Incidentally,

git lfs ls-files
git show HEAD:foo/bar/mega.csv

are helpful in determining if LFS has been set up correctly.

Upvotes: 0

bk2204
bk2204

Reputation: 76629

Your problem is the path you gave to git lfs migrate import. The path you provide needs to be suitable for a .gitattributes file, which means it must be specified in relation to the root of your repository. You provided an absolute path instead, which told Git LFS to match all the PDF files in a subdirectory called Temp under a directory in the root of your repository called C:. Such a directory cannot possibly exist on Windows, but could plausibly exist on a Unix system.

Instead, you want to specify the pattern as simply *.pdf, which will affect all the PDF files in your repository, wherever they may be located.

In addition, if you have multiple branches, or even if you don't, you usually want to migrate all branches, so you should pass --everything. So your invocation should look like git lfs migrate import --everything --include="*.pdf".

Upvotes: 2

Related Questions