Git and Filesystems: Empty Folders, Modes and LF
Git tracks paths and content, not every filesystem property
In the filesystem fixture, empty/ exists but has no file. An ordinary Git commit records files and tree entries needed for them, not standalone empty directories. Put a meaningful placeholder file in an otherwise empty directory if you need it in a checkout; .gitkeep is only a convention. Git does not preserve general ownership, timestamps or every permission bit in commits.
git ls-files -- empty/printf "Reserved for examples\n" > empty/README.txtgit add -- empty/README.txtgit ls-files -- empty/The first command prints nothing. After adding the placeholder, the index lists empty/README.txt. In this Linux fixture, the directory can now be recreated from a commit containing that file.
Executable modes and symbolic links
Git distinguishes regular non-executable files (100644), executable files (100755) and symbolic links (120000). On this Linux fixture the tracked run.sh starts non-executable and link.txt points to notes.txt. chmod +x changes the executable bit; stage the path to record it. A symlink stores its target text, not the contents of the destination.
chmod +x run.shgit add -- run.shgit ls-files --stage -- run.sh link.txtgit show :link.txtThe index shows 100755 for run.sh and 120000 for link.txt; the latter’s stored contents are notes.txt (no trailing newline in this fixture). Windows filesystems and Git configuration may not expose mode changes or symlinks in the same way. On systems without meaningful mode detection, git add --chmod=+x -- run.sh explicitly changes the index mode. Case-only renames and filename encodings also depend on platform; inspect status and coordinate rather than changing global safety settings.
Normalize text line endings with attributes
LF and CRLF are different byte sequences used for line endings. In the fixture, .gitattributes contains *.txt text eol=lf and sample.txt has CRLF on disk. A repository policy can normalize text in the index and choose checkout line endings. It does not magically rewrite all existing blobs. Do not normalize binary data as text.
git add -- .gitattributes sample.txtgit ls-files --eol -- sample.txtgit diff --cached --statThe fixture shows i/lf and w/crlf for sample.txt before checkout. The index stores LF even though the working copy still has CRLF. Changing a policy for existing files may require a separately reviewed renormalization; do not do that across a real project casually. Practice: explain why a mode-only change or an empty directory may look different on another OS.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git and Filesystems: Empty Folders, Modes and LF — knowledge check
Apply the file management and ignore rules taught in this lesson.
How can a normally empty directory be represented in a commit?
Which mode represents an executable ordinary file?
What does a Git symlink entry store?
What does i/lf and w/crlf mean in git ls-files --eol?
Which is a safer way to share text line-ending policy?