By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
git add
git commit
git status
git diff
A Hyper-Practical, Zero-Fluff Study Guide
Git’s snapshotting commands (git add, git commit, git status, git diff) are the atomic unit of version control. They let you: - Capture changes to your codebase at a point in time.- Inspect what’s changed, staged, or untracked.- Debug regressions by comparing versions.- Collaborate safely by sharing only intentional changes.
Why this matters in production:- You’re a DevOps engineer and a deployment fails. You need to roll back to the last known good commit—but only if you’ve been committing properly.- You inherit a legacy codebase with no commit history. You must reconstruct what changed between versions to debug a critical bug.- You’re working in a team and someone breaks the build. git diff and git status help you identify exactly what changed before merging.- You’re preparing for a certification (e.g., GitHub Actions, AWS DevOps Pro) and need to explain how Git tracks changes in CI/CD pipelines.
If you ignore snapshotting:- You lose the ability to undo mistakes (no git reset, no git revert).- You pollute the commit history with half-baked changes, making debugging a nightmare.- You accidentally commit secrets (API keys, passwords) because you didn’t check git status before committing.
git reset
git revert
.git
.git/
git diff --staged
git add .
git add -p
a1b2c3d
git show a1b2c3d
git reset HEAD~1
git --version
mkdir my-project && cd my-project
Goal: Initialize a repo, make changes, stage them, commit, and inspect differences.
mkdir git-snapshotting-demo && cd git-snapshotting-demo git init
Expected Output:
Initialized empty Git repository in /path/to/git-snapshotting-demo/.git/
echo 'print("Hello, Git!")' > app.py git status
On branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) app.py nothing added to commit but untracked files present (use "git add" to track)
Key Takeaway:- app.py is untracked (Git sees it but isn’t tracking changes yet).
app.py
git add app.py git status
On branch main No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: app.py
Key Takeaway:- app.py is now staged (ready to commit).
git commit -m "Add initial Python script"
[main (root-commit) a1b2c3d] Add initial Python script 1 file changed, 1 insertion(+) create mode 100644 app.py
Key Takeaway:- The commit is now permanently stored in Git’s history.- The hash (a1b2c3d) uniquely identifies this commit.
echo 'print("Goodbye, Git!")' >> app.py git diff
diff --git a/app.py b/app.py index 8a0f0f4..e69de29 100644 --- a/app.py +++ b/app.py @@ -1 +1,2 @@ print("Hello, Git!") +print("Goodbye, Git!")
Key Takeaway:- git diff shows unstaged changes (the new line isn’t staged yet).
git add app.py git commit -m "Add farewell message"
[main 4e5f6g7] Add farewell message 1 file changed, 1 insertion(+)
git log
git log --oneline
4e5f6g7 (HEAD -> main) Add farewell message a1b2c3d Add initial Python script
Key Takeaway:- HEAD points to the latest commit (4e5f6g7).- --oneline shows a compact history.
HEAD
4e5f6g7
--oneline
git diff a1b2c3d 4e5f6g7
Key Takeaway:- This shows what changed between two commits.
.env
.gitignore
bash echo ".env" >> .gitignore echo "*.pem" >> .gitignore
git-secrets
pre-commit
git bisect
node_modules/
.zip
fix bug
Fix 500 error in /login endpoint (missing user validation)
<type>(<scope>): <subject> <BLANK LINE> <body>
git tag v1.0.0
git count-objects -vH
git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | awk '/^blob/ {print substr($0,6)}' | sort --numeric-sort --key=2 | tail -n 10
git blame
git blame app.py
<type>(<scope>): <subject>
git commit -a
-a
✅ "It stages changes for the next commit."
"How do you see unstaged changes?"
✅ git diff
"What’s the difference between git diff and git diff --staged?"
✅ git diff --staged = staged changes (staging vs. last commit).
"How do you undo a git add?"
git reset <file>
❌ git commit --amend (that’s for commits).
git commit --amend
"What’s the default editor for git commit if no -m is provided?"
-m
core.editor
git add -u
Scenario:You ran git add . and committed, but you accidentally included a debug.log file with sensitive data. Undo the commit, remove the file, and recommit properly.
debug.log
Solution:
# Undo the last commit (keeps changes in working dir) git reset HEAD~1 # Remove debug.log from staging (if it was staged) git reset debug.log # Add debug.log to .gitignore echo "debug.log" >> .gitignore # Stage and commit the correct files git add .gitignore app.py git commit -m "Add .gitignore and update app"
Why It Works:- git reset HEAD~1 undoes the commit but keeps changes in the working directory.- git reset debug.log unstages the file.- .gitignore ensures debug.log is never tracked again.
git reset debug.log
-s
--staged
git add <file>
-p
-m "message"
--hard
git rm --cached <file>
git show <commit>
⚠️ Exam Traps:- git commit -a skips the staging area (commits all tracked changes).- git reset --hard deletes uncommitted changes permanently.- git diff only shows unstaged changes (use --staged for staged changes).
git reset --hard
Final Pro Tip:
"A good commit is like a good tweet: short, clear, and useful. A bad commit is like a rambling email—no one reads it, and it clutters history."
Now go commit something useful! ?
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.