Skip to content

How to diff files tracked by Git LFS #440

Closed

Description

@eric-brechemier

I would like to see a difference between subsequent versions of a file tracked by Git LFS, which I used to get using git log -p.

Is there an alternate command to get this difference with Git LFS? Are there any plans to integrate this command to display differences in file contents, rather than differences between pointer references, when using git diff or git log -p?

Note: I am using Git LFS to track (somewhat large) text files.

Activity

  1. whoisj commented on Jun 25, 2015

    @whoisj

    Unless git lfs diff is a working command, I do not see how Git would have any knowledge of what the worktree values of the files are and therefore no mechanism to help you diff them.

  2. eric-brechemier commented on Jun 26, 2015

    @eric-brechemier
    Author

    @whoisj my point exactly. I actually looked for a git lfs diff command but could not find one:
    https://github.com/github/git-lfs/tree/master/docs/man

    Are there any plans to develop this utility? How would it be done? Can I implement it myself (if noone has done it before) in the meantime?

  3. michael-k commented on Jun 26, 2015

    @michael-k
    Contributor
  4. eric-brechemier commented on Jul 1, 2015

    @eric-brechemier
    Author

    @michael-k Excellent, thanks. I did not know that the LFS files were stored as plain text (for text files) inside the .git/lfs/objects folder.

    If I understand correctly, the same method could be used to write a diff driver:
    http://git-scm.com/docs/gitattributes#_defining_an_external_diff_driver

  5. technoweenie commented on May 10, 2016

    @technoweenie
    Contributor

    Hey all, just going back through old issues that were never triaged. It's doubtful that we'll have a git lfs diff command that knows how to handle file types. But, LFS does add a diff=lfs to gitattributes, so there's potentially a way we could provide some way for custom diff tools to tie into LFS. I'm not sure how well that'd work on the command line though.

  6. samuelcolvin commented on Mar 14, 2017

    @samuelcolvin

    This would be extremely useful. I've just started using lfs for large json files, it's pretty annoying I can no longer review changes with git diff.

    I'm tempted to disable lfs until the files get so large I'm forced to use it.

  7. biswajitind commented on Sep 6, 2018

    @biswajitind

    Interestingly if we use an external diff command, It works

    Try this
    git difftool -y --extcmd='/usr/bin/diff -c'

    and in .gitattribute file have
    *.json filter=lfs diff=lfs merge=lfs -text

  8. ruuda commented on Jan 4, 2019

    @ruuda

    Interestingly if we use an external diff command, It works

    We can even use Git's diff:

    git difftool --no-prompt --extcmd='/usr/bin/git diff --no-index'
    
  9. shuprash commented on Jun 11, 2019

    @shuprash

    Is the git lfs diff feature available now. I am new to git and git lfs. I would like to have the diff to see the differences in the documents checked in to GIT LFS. Can someone pls suggest, how I can use the difftool command to achieve this. Where should this command be configured?

  10. bk2204 commented on Jun 11, 2019

    @bk2204
    Member

    There is still no git lfs diff feature. You can use the git difftool command mentioned above with git diff --no-index to view files, or you can use git diff --no-index itself to diff two files on disk.

  11. bk2204 commented on Jun 11, 2019

    @bk2204
    Member

    Another option if you want to have diffs is to run git config diff.lfs.textconv cat, which will have any files with the diff=lfs attribute automatically rendered through Git to show the LFS file instead of the pointer.

  12. Daahrien commented on Aug 7, 2020

    @Daahrien

    Hello! Im new to LFS I would like to know if files in LFS are treated the same as any other file in the repo? I mean, are only the differences saved or when I change the file does it get saved whole again?

    so if I have a file of 10 MB and commit/push and then I change it and now its 20 MB, I commit/push again, is there 30 MBs now or 20 MB + the differences. I hope I made myself clear :p Thank you.

  13. chrisd8088 commented on Aug 7, 2020

    @chrisd8088
    Member

    Hi @lestat, thanks for your question. In general, it's better to open a new issue than comment on one that's closed, unless it's directly related to your question.

    In brief, no, LFS files are not treated identically to other files in the repo; that's sort of the crux of the issue. They are instead stored separately, and are not stored in the repo as deltas (diffs) against previous versions. There are lots of good tutorials out there, such as this one and the associated video, which might help explain some of the concepts.

  14. sjackman commented on Jan 15, 2021

    @sjackman

    git config diff.lfs.textconv cat was the fix that I was looking for! It's useful particularly for large text files in Git LFS, like e.g. JSON. Any thoughts on making adding that config by default after git lfs install?

  15. bk2204 commented on Jan 15, 2021

    @bk2204
    Member

    git config diff.lfs.textconv cat was the fix that I was looking for! It's useful particularly for large text files in Git LFS, like e.g. JSON. Any thoughts on making adding that config by default after git lfs install?

    Since a lot of the files that people store in Git LFS are binary files, such as images, I'm not sure that such an option would be a sensible default. I've documented it in the FAQ, though.

  16. sjackman commented on Jan 15, 2021

    @sjackman

    Makes sense. Thanks for updating the FAQ!

  17. m27315 commented on Jul 16, 2021

    @m27315

    git config diff.lfs.textconv cat was the fix that I was looking for! It's useful particularly for large text files in Git LFS, like e.g. JSON. Any thoughts on making adding that config by default after git lfs install?

    Since a lot of the files that people store in Git LFS are binary files, such as images, I'm not sure that such an option would be a sensible default. I've documented it in the FAQ, though.

    To address above concern, please see #4551.

  18. added a commit that references this issue on Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions