Git Diff
Part of the Version Control section of Coddy's Terminal journey — lesson 15 of 58.
git diff shows you exactly what has changed in your working directory since the last commit. It is one of the most useful commands when you are mid-edit and want to remember what you have done.
git diffLines that were removed are prefixed with -; lines that were added are prefixed with +:
-print("hi")
+print("hello")By default git diff compares the working directory to what was last committed. It does not show changes that are already staged. Run it before staging to review your edits one last time.
Unchanged context lines around your changes appear with a leading space, so you can see where the change happened in the file.
Challenge
EasyThe folder contains greet.py with the line print("hi"), already committed. Change the line to print("hello"), then run git diff to see your unstaged change.
Cheat sheet
git diff shows changes in the working directory since the last commit (unstaged changes only):
git diffRemoved lines are prefixed with -, added lines with +:
-print("hi")
+print("hello")Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Version Control
2Getting Started
Initialize A RepositoryThe .git FolderConfigure Your IdentityGit StatusRecap - First Repo8Merging
What Is A MergeFast-Forward MergeThree-Way MergeMerge ConflictsResolve A ConflictRecap - Merge Master11Feature Branch Project
Project OverviewInitialize Main3Tracking Changes
The Staging AreaGit AddGit CommitModifying A Tracked FileGit LogRecap - First Commits6Recipe Site Project
Project OverviewInitialize And Ignore