Test with LFS-Tracked Files
In this final step, we will add the LFS-tracked file to the Git staging area and commit it. This will demonstrate how Git LFS handles the file differently from regular files.
First, ensure you are in the correct directory:
cd ~/project/my-time-machine
We have already created the large_image.png
file and configured Git LFS to track .png
files in the previous steps. Now, let's add the file to the staging area using git add
:
git add large_image.png
This command stages the file for the next commit. Git LFS intercepts this operation for large_image.png
because it matches the pattern in .gitattributes
. Instead of adding the entire file content to the Git index, Git LFS adds a small "pointer" file.
Let's check the status to see the staged file:
git status
You should see output indicating that large_image.png
is a new file ready to be committed:
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: .gitattributes
new file: large_image.png
Notice that .gitattributes
is also staged because we modified it in Step 1.
Now, let's commit the changes:
git commit -m "Add LFS tracked image placeholder"
You should see output similar to this:
[master (root-commit) abcdefg] Add LFS tracked image placeholder
2 files changed, X insertions(+)
create mode 100644 .gitattributes
create mode 100644 large_image.png
The commit message confirms that both .gitattributes
and large_image.png
were committed. However, the actual content of large_image.png
is not stored directly in the Git commit. Instead, the commit stores the small pointer file, and the large file content is managed by Git LFS.
To see the difference, let's look at the content of the file as stored in Git using git show
. This command shows the content of a file at a specific commit.
git show HEAD:large_image.png
You should see output similar to this:
version https://git-lfs.github.com/spec/v1
oid sha256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
size 31
This is the content of the pointer file, not the actual "This is a large image file placeholder." text. This demonstrates that Git is storing a reference to the large file, while Git LFS is managing the actual file content.
This is the core concept of Git LFS: keeping the main Git repository lightweight by storing only pointers to large files, while the large file content is stored separately.