Skip to content

Some git-lfs tracked files shown as modified after git clone #3787

Closed

Description

@wrightsg

Environment: git-lfs 2.8.0 in MSYS2 (64-bit) on Windows 10.

We are tracking our documentation (*.docx, *.pdf, *.vsd) using git-lfs.

After a fresh git clone some of these files show up as modified.

I have verified that

  • The files in question are actually stored in our Bitbucket repository using git lfs
  • git lfs install was executed before clone
  • The files are properly tracked in the .gitattributes file (exactly the same as other files in the same location which do not have this issue)

Based on suggestion from other similar issues I ran git lfs migrate import. It does not rewrite any commits but after the command finishes my working tree is clean (i.e. the previously modified files do no longer show up as modified). However, only the "pointer files" are checked out for the files that previously showed up as modified. If I run git lfs checkout to actually get the binary files they show up as modified again.

What makes this issue even weirder is that it is not completely reproducible. Sometimes after a fresh git clone 3 files show up as modified, sometimes its only 2 of them. What is consistent is that git status only seems to be happy if only the pointer file of these 3 files is present in the working tree.

Activity

  1. changed the title [-]Some git-lfs tracked files shown as modified after git checkout[/-] [+]Some git-lfs tracked files shown as modified after git clone[/+] on Aug 23, 2019
  2. bk2204 commented on Aug 23, 2019

    @bk2204
    Member

    Hey,

    Sorry to hear you're having trouble. I'm not sure exactly what's going on, but I have some questions to help figure it out.

    How are you tracking the documentation in the .gitattributes file? Are you using glob patterns or individual file names? Is there anything similar about the names of the files hat have this problem? Is Git producing any error messages when the checkout occurs? Does running the clone with GIT_TRACE=1 at a shell prompt produce anything useful or interesting (if you're not sure, you can paste or attach it here and I can look)?

  3. wrightsg commented on Aug 26, 2019

    @wrightsg
    Author
    • The files are tracked using individual file names in the .gitattributes file; the files are either in the same folder as the .gitattributes file itself or in a subfolder 1 level deeper (relative to .gitattributes)
    • File names are similar but there are other files tracked at the same location with equally similar file names (all caps with underscores) that seems to be handled correctly
    • No error messages when performing the initial git clone
    $ git clone ssh://git@xxx/xxx/sw.git
    Cloning into 'sw'...
    remote: Counting objects: 40405, done.
    remote: Compressing objects: 100% (4142/4142), done.
    remote: Total 40405 (delta 3488), reused 974 (delta 745)
    Receiving objects: 100% (40405/40405), 28.49 MiB | 8.25 MiB/s, done.
    Resolving deltas: 100% (28911/28911), done.
    Checking out files: 100% (1314/1314), done.
    Filtering content: 100% (56/56), 141.70 MiB | 11.56 MiB/s, done.
    
    • I cannot find anything interesting in the console output when running git clone with GIT_TRACE=1; the files in question show up in the list of LFS tracked files; I also see HTTP GET requests for all of the files that show up as modified later; please let me know if you are looking anything specific here; I would attach the log but there are some customer names in some of our files and I'd have to clean up the log first

    Furthermore I have to correct my observation that the files that sometimes show up as modified only show up as modified if their binary version is checked out. After running git clone a couple of times again I have also seen the situation where only one of the files shows up as modified (its binary file is checked out) and the other two files do not show up as modified (their binary files are checked out as well).

    Something I forgot to mention in the initial post is that some of the files might have been initially pushed from a machine where git lfs install had not been run, i.e. the binary file was actually pushed as binary file instead of to LFS storage. This was later rectified by deleting the binary file from git and committing/pushing again with git lfs install properly setup.

  4. bk2204 commented on Aug 26, 2019

    @bk2204
    Member

    Usually this problem occurs for one of a couple of reasons. One is the situation you describe in your last paragraph: the file is modified because it's tracked as a Git file but the file is listed in .gitattributes as an LFS file. In such a case, trying git cat-file blob "HEAD:test1.bin" | git lfs pointer --check --stdin (where you replace test1.bin with an affected file) should exit nonzero, and you can then run git lfs migrate import and commit the result to make sure that the file isn't modified.

    The other reason this can occur is that some process on the system is causing the file to be modified or stat-dirty. Sometimes this can be an editor or other tool that handles your binary files, especially on Windows, where timestamps are more important since we lack an inode number. I don't know how you'd go about testing this, but it is a possibility.

  5. wrightsg commented on Aug 26, 2019

    @wrightsg
    Author

    I ran the command you suggested on one of the files that shows up as modified but it returned 0.

    What still strikes me as extremely weird is that the issue is non-deterministic. I just had about 5 subsequent git clone runs where none of the files in question showed up as modified and they were all checked out properly as binary files in the file system. Only after the 6th attempt I could get some of the files to show up as modified again.

    There is no obvious time-stamp difference of the files that are shown as modified and those who do not.

    Running git checkout on the "modified" files has no effect. git says Updated X paths from the index but they still show up as modified afterwards.

    Do you have any additional ideas/suggestions?

  6. bk2204 commented on Aug 26, 2019

    @bk2204
    Member

    Do you have any additional ideas/suggestions?

    The process that writes these files to disk is actually Git; Git LFS just filters them in this case. I don't know of a reason that Git would think of them being modified, especially non-deterministically, after it's just written them.

    You could check the files by running sha256sum on the modified files and seeing if the hashes and sizes match the values in the pointer files (which you can see by running the git cat-file blob invocation I provided above, but without the pipe to git lfs pointer). That would tell you at least if there's a legitimate reason for them being modified.

    If they are indeed modified, you could look to see if you have some sort of antivirus or other tool that's causing a problem; that's a common source of problems with Git, so it wouldn't surprise me if it hit Git LFS as well. Beyond that, I don't have any other suggestions on tracking this down.

  7. wrightsg commented on Aug 27, 2019

    @wrightsg
    Author

    If I run git diff on one of the modifies files I get the following output.

    -version https://git-lfs.github.com/spec/v1
    -oid sha256:92f443377fb52dd71221d54cb8522119293159d5c0a812f0652356072ad579f6
    -size 648906
    +version https://git-lfs.github.com/spec/v1
    +oid sha256:92f443377fb52dd71221d54cb8522119293159d5c0a812f0652356072ad579f6
    +size 648906
    

    This matches the output when running sha256sum over the file manually.

    Interestingly if I run git diff -w (ignore whitespace) on the files, the output is empty. Could this somehow be whitespace related?

  8. bk2204 commented on Aug 27, 2019

    @bk2204
    Member

    Does your .gitattributes file contain a -text attribute for your binary files? It sounds like what might have happened is that these files are getting rewritten with CRLF line endings which they should not have.

    Which version of the file is the one with CRLF endings and which one has LF endings? Are there any other attributes in the .gitattributes file which set the text attribute? Also, do you have any settings that modify core.eol or core.autocrlf?

  9. wrightsg commented on Aug 28, 2019

    @wrightsg
    Author

    Yes, there is a -text attribute for all the binary files (this was automatically generated when using git lfs track).

    If I run git diff --ws-error-highlight=old on a file that shows up as modified I get the following output.

    -version https://git-lfs.github.com/spec/v1^M
    -oid sha256:ccb05f59bf727a908ae5d7a76b871d974c29cadc077d4e091df2e1947e2fed88^M
    -size 211456^M
    +version https://git-lfs.github.com/spec/v1
    +oid sha256:ccb05f59bf727a908ae5d7a76b871d974c29cadc077d4e091df2e1947e2fed88
    +size 211456
    

    This means that the "unmodified" file contains CRLF line endings which were replaced by LF line endings?

    All the .gitattributes entries look like this

    [file name] filter=lfs diff=lfs merge=lfs -text
    

    My local .gitconfig contains the following [core] section

    [core]
            repositoryformatversion = 0
            filemode = false
            bare = false
            logallrefupdates = true
            symlinks = false
            ignorecase = true
    

    My global .gitconfig contains the following [core] section

    [core]
            editor = emacs -nw
            autocrlf = true
    [filter "lfs"]
            process = git-lfs filter-process
            required = true
            clean = git-lfs clean -- %f
            smudge = git-lfs smudge -- %f
    
  10. bk2204 commented on Aug 28, 2019

    @bk2204
    Member

    If I run git diff --ws-error-highlight=old on a file that shows up as modified I get the following output.

    -version https://git-lfs.github.com/spec/v1^M
    -oid sha256:ccb05f59bf727a908ae5d7a76b871d974c29cadc077d4e091df2e1947e2fed88^M
    -size 211456^M
    +version https://git-lfs.github.com/spec/v1
    +oid sha256:ccb05f59bf727a908ae5d7a76b871d974c29cadc077d4e091df2e1947e2fed88
    +size 211456
    

    This means that the "unmodified" file contains CRLF line endings which were replaced by LF line endings?

    Yup. I have no idea why this would occur: we never write CRLF endings in a pointer file, only LF endings. This does definitely explain the problem, though, since if Git cleans the files, they'll then show up as modified. It's possible some other tool (or someone writing pointer files by hand) caused this issue.

    I think we probably need to reject pointer files with carriage returns, which I'll try to get to soon. As for your situation, I think you'll need to remove the carriage returns from any files that have them and commit, which should prevent Git from thinking that the files are modified.

  11. wrightsg commented on Aug 28, 2019

    @wrightsg
    Author

    Great - thanks!

    What is the best way for me to modify the pointer files directly? Clone the repo without git lfs installed and then run dos2unix on all pointer files?

  12. bk2204 commented on Aug 28, 2019

    @bk2204
    Member

    You can clone the repo with GIT_LFS_SKIP_SMUDGE=1, which will prevent the checkout of the large files, and then run dos2unix (or some other equivalent program) on the pointers.

  13. wrightsg commented on Aug 28, 2019

    @wrightsg
    Author

    This seems to have solved the issue (just did 10 clones as the problem would not always show up) - thank you!

    For anyone with the same problem, I used

    GIT_LFS_SKIP_SMUDGE=1 git clone <repo>.git
    cd <repo>
    git lfs ls-files | cut -d" " -f3 | xargs dos2unix {}
    git add -u .
    git commit -m 'fix git lfs pointer file line endings'
    git push
    

    I still have no idea how this happened (maybe a machine without git lfs installed cloned the repo, accidentally modified the pointer files and pushed them back?) or why the files showing up as modified is non-deterministic.

  14. JustinBuzon commented on Dec 17, 2019

    @JustinBuzon

    I have a very similar problem. My git diff shows the similar results containing version, oid, size, and no actual changes. This has been occurring after installing LFS and migrating info on a project that was about 6 months old without LFS.

    I tried
    git lfs ls-files | cut -d" " -f3 | xargs dos2unix {}
    but it did not solve the issue. I was hoping that I didn't have to clone the project again. Cloning 10 times to fix an issue sounds unpleasant - so I'm going to avoid it until it is the only thing that actually fixes it.

  15. bk2204 commented on Dec 17, 2019

    @bk2204
    Member

    Hey,

    I don't think that cloning multiple times fixes the issue; it's just that it appears that the files don't always appear modified for the original reporter. In order to fix the repository with that command, you'd need to clone the repo with GIT_LFS_SKIP_SMUDGE=1; did you do that? Also, does your .gitattributes file contain -text for your LFS files? If not, it should.

  16. 16 remaining items

  17. bk2204 commented on Feb 2, 2022

    @bk2204
    Member

    @mschuckmann Can you provide the output of .gitattributes? Does git add --renormalize . result in any changes on your system? What does git diff --ws-error-highlight=all show on the affected files? Does git lfs fsck --pointers pass on this commit (you need 3.0 or newer for that)?

  18. mschuckmann commented on Feb 2, 2022

    @mschuckmann

    @bk2204 I had just run a pipeline build with the git diff --ws-error-highlight=all command along with some other commands.
    Here is the output, (hint the output it is not helpful)

    + git --version
    git version 2.17.1
    
    + git lfs --version
    Sorry, no usage text found for "git-lfs"
    Error: unknown flag: --version
    
    
    + git status
    On branch feature/resolve-pipeline-dirty-issue
    Your branch is up to date with 'origin/feature/resolve-pipeline-dirty-issue'.
    
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
    
    	modified:   binaries/u-boot.elf
    	modified:   design_1_xsa/design_1_wrapper.xsa
    
    no changes added to commit (use "git add" and/or "git commit -a")
    
    + git lfs status
    On branch feature/resolve-pipeline-dirty-issue
    Git LFS objects to be pushed to origin/feature/resolve-pipeline-dirty-issue:
    
    
    Git LFS objects to be committed:
    
    
    Git LFS objects not staged for commit:
    
    	binaries/u-boot.elf (LFS: 173ff22 -> File: 173ff22)
    	design_1_xsa/design_1_wrapper.xsa (LFS: 75a6c0d -> File: 75a6c0d)
    
    
    + git diff --ws-error-highlight=old
    diff --git a/binaries/u-boot.elf b/binaries/u-boot.elf
    index 247501c..0885601 100644
    Binary files a/binaries/u-boot.elf and b/binaries/u-boot.elf differ
    diff --git a/design_1_xsa/design_1_wrapper.xsa b/design_1_xsa/design_1_wrapper.xsa
    index 0975809..ade4637 100644
    Binary files a/design_1_xsa/design_1_wrapper.xsa and b/design_1_xsa/design_1_wrapper.xsa differ
    
  19. mschuckmann commented on Feb 2, 2022

    @mschuckmann

    @bk2204 Here is the contents of the .gitattributes file:

    * text=auto
    *.bit filter=lfs diff=lfs merge=lfs -text
    *.xsa filter=lfs diff=lfs merge=lfs -text
    *.elf filter=lfs diff=lfs merge=lfs -text
    *.bin filter=lfs diff=lfs merge=lfs -text
    
  20. mschuckmann commented on Feb 2, 2022

    @mschuckmann

    @bk2204 with respect to your question about git add --renormalize . do you want me to run it when git is reporting one or more of the files as modified or just run the command in general?

  21. bk2204 commented on Feb 2, 2022

    @bk2204
    Member

    @bk2204 with respect to your question about git add --renormalize . do you want me to run it when git is reporting one or more of the files as modified or just run the command in general?

    I want you to run it in your local copy on an otherwise clean working tree and see if it causes any files to show as modified in the git status output. If it does, I want you to commit that change and then see if it fixes the problem. This is the documented fix in the Git FAQ for this case.

  22. mschuckmann commented on Feb 2, 2022

    @mschuckmann

    @bk2204 I ran the git add --renormalize . command on a freshly cloned repo and git doesn't show any modified files.

  23. mschuckmann commented on Feb 2, 2022

    @mschuckmann

    Also note I'm not on Windows, this is all Linux, I suppose it's possible that sometime in the past someone used Windows to commit these files but I don't know.

  24. bk2204 commented on Feb 2, 2022

    @bk2204
    Member

    Your problem is that you don't have Git LFS installed in the container or it's not appropriately configured. When you push data into a container, all the information in the index is incorrect because the device and inode numbers change, so Git re-reads all of the data anytime you refresh the index.

    When you do that, Git asks to clean the LFS files, but since Git LFS isn't enabled in the container, those files are no longer reflected as LFS pointer files, but as Git files, which is different from what's in the index, and they're marked as modified.

    Either don't refresh the index in the container (that is, avoid running Git) or install Git LFS and make sure that git lfs install has run (or, if your distro sets things up properly, like Debian's packages, then you don't have to).

  25. mschuckmann commented on Feb 2, 2022

    @mschuckmann

    @bk2204 So git-lfs is installed in the container, it was done as part of the docker image build using apt install like so:

    apt-get upgrade -y -qq && \
        apt-get install -y -qq --no-install-recommends \
            git \
            git-lfs \ 
            git-flow \
        apt-get clean && \
        apt-get autoclean
    

    The image does not explicitly run git lfs install as I was under the impression that the package install handled that but I can add that to the image build if it will fix the problem.
    Also note that in the log I posted above the pipeline ran git lfs status and it did report results consistent with the results produced by git status so I'm relatively certain that git-lfs is installed and at least partially working.

  26. mschuckmann commented on Feb 2, 2022

    @mschuckmann

    I'm not sure what you mean by push data into a container in my case the clone of the repo is happening in the context of the container in fact the git clone command is one of the first commands run inside the container when the pipeline is run.

  27. bk2204 commented on Feb 2, 2022

    @bk2204
    Member

    You shouldn't see this output when you run git diff:

    + git diff --ws-error-highlight=old
    diff --git a/binaries/u-boot.elf b/binaries/u-boot.elf
    index 247501c..0885601 100644
    Binary files a/binaries/u-boot.elf and b/binaries/u-boot.elf differ
    diff --git a/design_1_xsa/design_1_wrapper.xsa b/design_1_xsa/design_1_wrapper.xsa
    index 0975809..ade4637 100644
    Binary files a/design_1_xsa/design_1_wrapper.xsa and b/design_1_xsa/design_1_wrapper.xsa differ
    

    Diff output when you have a file that's correctly being tracked as LFS looks like this:

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

    In other words, what you should see in the diff is the pointer file, not binary content. If you're seeing that, then either the file already in the repository is not LFS file, in which case you need to use git add --renormalize . to fix that, or the file in the working tree appears to be modified to Git (for whatever reason) and LFS is not properly configured.

    This is also slightly concerning:

    + git lfs --version
    Sorry, no usage text found for "git-lfs"
    Error: unknown flag: --version
    

    You may have a very old version, in which case git lfs version would be helpful. I don't know what OS you're using here, but it looks like it may be Ubuntu 18.04, in which case you may have found an issue which is fixed in a newer version.

    This output indicates that it looks like your file is an LFS file in the repository, and something is trying to turn it into something else here:

    Git LFS objects not staged for commit:
    
    	binaries/u-boot.elf (LFS: 173ff22 -> File: 173ff22)
    	design_1_xsa/design_1_wrapper.xsa (LFS: 75a6c0d -> File: 75a6c0d)
    

    Without a reproducible example against the latest release, I can't really say what the problem is for certain.

  28. mschuckmann commented on Feb 2, 2022

    @mschuckmann
  29. mschuckmann commented on Feb 7, 2022

    @mschuckmann

    @bk2204 Updating the version of git and git-lfs in docker seems to have resolved the issue.
    Thank you for the help.

  30. bk2204 commented on Feb 7, 2022

    @bk2204
    Member

    Okay, great. I think all the issues here have been addressed independently or at least root causes have been found, so I'm going to close this. If folks see similar behavior in the future, please open a new issue or discussion as appropriate and we'll try to investigate.

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