Home > Software design >  How can we see the reference file inside our repo after adding the file with git lfs?
How can we see the reference file inside our repo after adding the file with git lfs?

Time:12-07

I have pushed a file using git-lfs in github. After pushing it, I can only see .gitattribute file changed under my commit in github like this:

file_name filter=lfs diff=lfs merge=lfs -text 

There are couple of questions I want to ask:

  1. Is .gitattribute file supposed to be changed only? Git lfs stores the reference of the file inside our repo. That reference file should be added in our repo right? Why can't I see that reference file under my commit in github?

  2. Actual file is pushed in a different server. From where exactly can we view it?

  3. Now when my branch gets merged with master branch, can other team members be able to access that file simply by adding git pull origin master? Obviously after they have properly configured git LFS.

  4. git lfs ls-files is not showing any files after adding it. Why is this so?

CodePudding user response:

When you push a file using Git LFS, the file itself is not added to your repository. Instead, a reference to the file is added to your repository, along with a .gitattributes file that specifies which files are tracked by Git LFS. The reference file is not visible in GitHub, as it is stored on the Git LFS server.

You can view the actual file by using the git lfs cat command, or by using a Git LFS client to download the file from the Git LFS server.

Other team members who have properly configured Git LFS on their systems will be able to access the file by pulling the latest changes from the master branch. However, they will only be able to download the file if they have access to the Git LFS server where the file is stored.

If the git lfs ls-files command is not showing any files, it is likely that the files you are looking for are not being tracked by Git LFS. You can use the git lfs track command to specify which files you want Git LFS to track. For example, if you want to track all files with the .png extension, you can run the following command:

git lfs track "*.png"

CodePudding user response:

  1. The .gitattributes should change to reflect that files with this pattern will be handled by LFS, but it should not be the only thing that has happened. The file itself should also be added and show up as modified, because the pointer file is updated every time you change a binary tracked by LFS.
  2. The actual binary is stored elsewhere, each git hosting provider can choose where to store these files. GitHub puts these files in a cloud storage provider's blob storage. But the UI will list the file and handle the redirects on the server. Git-lfs will handle the download and replacement locally, if configured properly.
  3. In the current state your changed will not be merged, since the file isn't stored in LFS.
  4. That's the big question. So, which commands did you run and what did git status tell you?

After successfully pushing your files to GitHub, they are marked as "LFS" when you try to view them:

enter image description here

enter image description here

note a file that has previously been committed won't suddenly be converted to LFS by calling git lfs track. The next changes may. In some cases you may want to migrate the history of your repo over to LFS, this will rewrite history, change your commit-shas and will require force-push.

  • Related