Skip to content

git-lfs does not track empty files #2447

Closed

Description

@mathstuf

I have an empty file I'd like LFS to track so that I can test whether LFS is set up properly during the build. However, LFS seems to ignore the attribute for empty (or too small?) files.

Activity

  1. mathstuf commented on Jul 27, 2017

    @mathstuf
    ContributorAuthor

    Yeah, files with little content are also skipped.

  2. technoweenie commented on Jul 28, 2017

    @technoweenie
    Contributor

    Most of the LFS test cases are for really tiny files. We even have a test dedicated to empty files. However, LFS essentially passes empty files through, so they still result in empty Git blobs. The smallest pointer that LFS can generate is for a 1 byte file.

    diff --git a/1.bin b/1.bin
    new file mode 100644
    index 0000000..55180c0
    --- /dev/null
    +++ b/1.bin
    @@ -0,0 +1,3 @@
    +version https://git-lfs.github.com/spec/v1
    +oid sha256:6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
    +size 1

    What files are you adding? What does your .gitattributes look like?

  3. mathstuf commented on Jul 28, 2017

    @mathstuf
    ContributorAuthor

    I'm trying to add an empty file so that our build system can detect whether LFS was actually used before adding tests which would otherwise read the raw pointer files and fail. The "small content" file I tried was writing LFS sentinel\n to a file; it went through untouched. This is the commit which adds the file LFS is ignoring (the small content test was done by git commit --amend on that file, so maybe there's something going wrong there?).

    IMO, if filter=lfs is used, LFS should do its thing and make a pointer file. Where in the spec does it specify that an empty file is a valid LFS pointer?

    Here is the .gitattributes change commit (it works for all other files under that directory).

  4. technoweenie commented on Jul 28, 2017

    @technoweenie
    Contributor

    Hmm, it worked fine for me. I tried adding your .gitattributes changes, and creating a couple dummy files:

    diff --git a/.gitattributes b/.gitattributes
    index 4edd5ac..cce770a 100644
    --- a/.gitattributes
    +++ b/.gitattributes
    @@ -1 +1,3 @@
     *.bin filter=lfs diff=lfs merge=lfs -text
    +[attr]lfs       filter=lfs diff=lfs merge=lfs -text
    +data/**         lfs
    diff --git a/data/bar b/data/bar
    new file mode 100644
    index 0000000..90353d7
    --- /dev/null
    +++ b/data/bar
    @@ -0,0 +1,3 @@
    +version https://git-lfs.github.com/spec/v1
    +oid sha256:98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
    +size 3
    diff --git a/data/foo b/data/foo
    new file mode 100644
    index 0000000..e69de29
    

    Keep in mind that .gitattributes changes only take affect on files that are added through git add or git commit -a after the change. It's up to Git to call LFS based on those matched patterns. We have no control over when that happens. Is it possible the LFS sentinel file was added before the .gitattributes?

  5. mathstuf commented on Jul 28, 2017

    @mathstuf
    ContributorAuthor

    The ~2 commit of the sentinel file is the attributes change.

  6. mathstuf commented on Jul 28, 2017

    @mathstuf
    ContributorAuthor

    Running under GIT_TRACE=1 and adding that cmb-data file:

    % git add cmb-data
    13:03:54.434316 git.c:350               trace: built-in: git 'add' 'cmb-data'                                                                                                                                                                                                                                                 
    13:03:54.435217 run-command.c:336       trace: run_command: 'git-lfs clean -- '\''data/cmb-data'\'''                                                                                                                                                                                                                          
    13:03:54.435360 run-command.c:195       trace: exec: '/bin/sh' '-c' 'git-lfs clean -- '\''data/cmb-data'\''' 'git-lfs clean -- '\''data/cmb-data'\'''
    
    % git check-attr -a cmb-data
    13:05:32.720566 git.c:350               trace: built-in: git 'check-attr' '-a' 'cmb-data'                                                                                                                                                                                                                                     
    cmb-data: diff: lfs                                                                                                                                                                                                                                                                                                           
    cmb-data: merge: lfs
    cmb-data: text: unset
    cmb-data: lfs: set
    cmb-data: filter: lfs
    

    The git tree shows a literal empty file. When trying to checkout this branch, I see this:

    Pointer file error: Unable to parse pointer at: "data/cmb-data"
    

    So even LFS doesn't like the literal empty file. I conclude that LFS really should turn it into a pointer since it doesn't pass an empty file through on the smudge side of the filtering.

  7. technoweenie commented on Jul 28, 2017

    @technoweenie
    Contributor

    I'm unable to replicate that error. What version of LFS are you using? If you can replicate that error in the test on the latest Git LFS release, that'd really help track this down. I agree that LFS should work with empty files.

    EDIT: To be clear, LFS should work with empty files. I don't think they need to be added to the Git repository as an LFS pointer though. It just seems wasteful. Adding a non-empty file for testing seems reasonable to me.

  8. mathstuf commented on Jul 28, 2017

    @mathstuf
    ContributorAuthor

    It was easier to test for empty content rather than a specific string, but then I hit this. Hmm, it looks like I may have gotten LFS a while ago; I'm using 1.5.5 on that machine.

  9. mathstuf commented on Jul 28, 2017

    @mathstuf
    ContributorAuthor

    With 2.2.1:

    % cat .gitattributes
    [attr]lfs       filter=lfs diff=lfs merge=lfs -text                                                                                                                                                                                                                                                                           
    *.lfs           lfs
    % touch 0.lfs
    % echo > 1.lfs
    % ll
    total 4                                
    -rw-r-----. 1 boeckb boeckb 0 Jul 28 14:16 0.lfs                               
    -rw-r-----. 1 boeckb boeckb 1 Jul 28 14:16 1.lfs                               
    % git add *.lfs
    % git diff --cached
    diff --git a/0.lfs b/0.lfs             
    new file mode 100644                   
    index 0000000..e69de29                 
    diff --git a/1.lfs b/1.lfs             
    new file mode 100644                   
    index 0000000..fd481aa                 
    --- /dev/null                          
    +++ b/1.lfs                            
    @@ -0,0 +1,3 @@                        
    +version https://git-lfs.github.com/spec/v1                                    
    +oid sha256:01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b   
    +size 1                                
    
  10. mathstuf commented on Jul 28, 2017

    @mathstuf
    ContributorAuthor

    Here's something a bit more structured and from the start:

    % git init
    Initialized empty Git repository in /home/boeckb/misc/code/sb/lfs-empty/.git/
    % git lfs install --local
    Updated git hooks.
    Git LFS initialized.
    % cat > .gitattributes <<EOF
    heredoc> [attr]lfs    filter=lfs diff=lfs merge=lfs -text
    heredoc> *.lfs        lfs
    heredoc> EOF
    % git add .gitattributes 
    % git commit -m add\ gitattributes
    [master (root-commit) 883249f] add gitattributes
     1 file changed, 2 insertions(+)
     create mode 100644 .gitattributes
    % touch 0.lfs
    % echo > 1.lfs
    % git add *.lfs
    % git commit -m add\ lfs\ files
    [master 699384c] add lfs files
     2 files changed, 3 insertions(+)
     create mode 100644 0.lfs
     create mode 100644 1.lfs
    % git log -p -n1
    commit 699384cd5bd292e101ffc33616c025fe4386684d
    Author: Git LFS Tests <[email protected]>
    Date:   Fri Jul 28 14:25:09 2017 -0400
    
        add lfs files
    
    diff --git a/0.lfs b/0.lfs
    new file mode 100644
    index 0000000..e69de29
    diff --git a/1.lfs b/1.lfs
    new file mode 100644
    index 0000000..fd481aa
    --- /dev/null
    +++ b/1.lfs
    @@ -0,0 +1,3 @@
    +version https://git-lfs.github.com/spec/v1
    +oid sha256:01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
    +size 1
    % git lfs version
    git-lfs/2.2.1 (GitHub; linux amd64; go 1.8.3; git 621d1f82)
    % git --version
    git version 2.9.4
    

    Also, fun…LFS's test suite modifies the global git configuration. Glad I caught that…

  11. technoweenie commented on Jul 28, 2017

    @technoweenie
    Contributor

    Cool. That looks correct to me. IIRC, there was some other issue with zero length blobs, and the fix was basically passing them through to Git. Sounds like you were just on an old version of LFS.

  12. mathstuf commented on Jul 28, 2017

    @mathstuf
    ContributorAuthor

    OK. Could the spec be updated to indicate that an empty file is also a valid LFS pointer then?

  13. technoweenie commented on Jul 28, 2017

    @technoweenie
    Contributor

    Sure, that's a great idea for clarification.

  14. added a commit that references this issue on Jul 28, 2017
    3678c8e
  15. mloskot commented on Jan 10, 2019

    @mloskot
    Contributor

    git-lfs/docs/spec.md

    Lines 23 to 24 in 3678c8e

    An empty file is the pointer for an empty file. That is, empty files are
    passed through LFS without any change.

    Could anyone clarify the passing through LFS?

    • Does it mean an empty file is supposed to be actually stored in LFS?
    • Is git lfs ls-files expected to list an empty file?

    For example, using

    $ git --version && git lfs --version
    git version 2.20.1.windows.1
    git-lfs/2.6.1 (GitHub; windows amd64; go 1.11.1; git dc072c3e)
    
    • Does this attempt to track empty file with LFS look correct?
    $ git init && git lfs install
    Initialized empty Git repository in F:/_git/empty-file-in-lfs/.git/
    Updated git hooks.
    Git LFS initialized.
    
    (master) $ git lfs track '*.bin'
    Tracking "*.bin"
    (master) $ touch empty.bin
    (master) $ git add empty.bin
    (master) $ git lfs status
    
    Git LFS objects to be committed:
    
            empty.bin (Git: e3b0c44)
    
    Git LFS objects not staged for commit:
    
    (master) $ git ci -m "Add empty.bin"
    [master (root-commit) 500f4da] Add empty.bin
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 empty.bin
    (master) $ git lfs ls-files
    (master) $ git show HEAD:empty.bin
    (master) $
    
    • If empty.bin is tracked by LFS, then why git lfs ls-files does not list it?
    • If empty.bin is not tracked by LFS, then git lfs status is confusing.
  16. mathstuf commented on Jan 10, 2019

    @mathstuf
    ContributorAuthor

    Does it mean an empty file is supposed to be actually stored in LFS?

    Well, you conceptually it is as far as git-lfs is concerned; it just elides out actually asking for 0 bytes from the server.

    Is git lfs ls-files expected to list an empty file?

    Hmm. I'd expect that it would since it has the attribute set.

  17. ttaylorr commented on Jan 26, 2019

    @ttaylorr
    Contributor
    • Does it mean an empty file is supposed to be actually stored in LFS?
    • Is git lfs ls-files expected to list an empty file?

    I think the answer is two "no"s here: the pointer representation of an empty file is the empty file (for historical reasons, perhaps we would do it differently today). Since the representation is idempotent, it's the case that Git LFS does not pay attention to the file at all, e.g., it does not show up in the list of git lfs ls-files, or be stored in .git/lfs/objects, etc.

  18. mloskot commented on Jan 27, 2019

    @mloskot
    Contributor

    @ttaylorr Thanks for the explanation.

  19. slonopotamus commented on Oct 16, 2019

    @slonopotamus
    Contributor

    See #3863. I believe that the statement you added to the spec only harms things because it adds unnecessary special case in git-lfs where bugs hide.

  20. mathstuf commented on Oct 16, 2019

    @mathstuf
    ContributorAuthor

    The statement was added in response to the current behavior of git-lfs (I wanted size 0 to be a thing, but the implementation did not behave that way). It seems that behavior has changed around this (lack of test coverage?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions