Course contentsShow
← Data Science
Lesson 2004 of 2,14546. Version Control with GitFree lesson

Inspecting Specific Files and Commits

Combine `git log`, `git show`, and `git diff` with file paths to trace changes to specific files over time.

Inspecting Specific Files and Commits

You'll learn how to focus Git's inspection tools on individual files to track their evolution through your project's history.

Understanding File-Specific History

When working on data science projects, you often need to understand how a particular script, notebook, or configuration file changed over time. Rather than wading through your entire project history, you can narrow Git's view to just the files you care about.

Think of it like filtering a security camera feed: instead of watching all cameras at once, you focus on the one hallway where something interesting happened.

Combining Commands with File Paths

You can append file paths to git log, git show, and git diff to isolate specific files:

# View all commits that modified a specific file
git log data_cleaning.py

# See what changed in that file in a specific commit
git show abc123 data_cleaning.py

# Compare how a file differs between two commits
git diff abc123 def456 data_cleaning.py

# See current working directory changes to one file only
git diff analysis.ipynb

This is invaluable when debugging: "When did I change that preprocessing step?" or "Who modified the model hyperparameters last month?"

Practical Workflow

You might start broad (git log) to find when issues appeared, then narrow down (git log model.py), then inspect specific changes (git show abc123 model.py). This lets you trace exactly how your feature engineering evolved or when a critical data transformation was introduced.

You can even combine this with log formatting options you learned earlier to create focused, readable histories of individual components.

Key Takeaway: Adding file paths to git log, git show, and git diff filters their output to specific files, letting you trace individual components' histories without noise from unrelated changes.