Git Staging Changes Quiz
Unlock the full potential of Git's staging area. Learn to craft precise commits by adding files, specific lines, or hunks, and master the tools to review and modify your staged changes.
Question 1
What is the primary purpose of the 'Staging Area' (or 'Index') in Git?
Question 2
You have modified `file.txt`. Which command moves these modifications from your working directory to the staging area?
Question 3
You have staged a file named `secret.txt` but realize you didn't mean to include it in the commit. You want to unstage it but keep your changes in the working directory. Which command is the modern, recommended way to do this?
Question 4
You run `git diff` and see no output, but you know you have changed files. However, when you run `git diff --staged`, you see your changes. What does this mean?
Question 5
You have made extensive changes to `script.js`. You want to stage only the first function you modified, not the entire file, to keep your commits small. Which command allows you to do this interactively?
Question 6
You have deleted a file `config.json` from your file system. `git status` shows it as 'deleted' but 'not staged for commit'. How do you stage this deletion?
Question 7
What is the difference between `git add .` and `git add -u`?
Question 8
You want to stage a file that is currently listed in your `.gitignore`. Git normally prevents this. How can you force Git to stage it anyway?
Question 9
When you stage a file, Git creates a 'blob' object. If you modify the file again and stage it again before committing, what happens to the previous blob?
Question 10
You have staged changes to `app.py`. You then make more edits to `app.py`. What does `git status` show for this file?
Question 11
Which command allows you to view the exact content of the file `main.js` as it currently sits in the staging area (Index), without looking at the working directory version?
Question 12
You want to remove a file `passwords.txt` from the repository (stop tracking it) but keep the file on your local hard drive. Which command does this?
Question 13
You are using `git add -p` and encounter a large block of changes (a hunk) that contains both a bug fix and a new feature. You want to stage only the bug fix. Which option in the interactive menu should you choose?
Question 14
What does `git diff --cached` do?
Question 15
You have renamed a file from `old.txt` to `new.txt` using your file explorer (not `git mv`). `git status` shows `deleted: old.txt` and `untracked: new.txt`. If you run `git add -A`, what will Git record?
Question 16
Which command displays a detailed list of every file currently in the staging area, including its mode, object name (SHA), and stage number?
Question 17
You want to stage changes to a file but ignore whitespace changes (like indentation fixes) to keep the diff clean. Which workflow is best?
Question 18
What happens if you try to commit when the staging area is empty (and you don't use the `-a` or `--allow-empty` flags)?
Question 19
You are resolving a merge conflict. You edit `conflict.txt` to remove the conflict markers and fix the code. What must you do next to mark the conflict as resolved?
Question 20
You have changed the file permissions of `script.sh` to be executable (`chmod +x script.sh`). `git status` shows this as a change. How do you stage this permission change?
Question 21
You want to undo all changes in your working directory and restore it to match the current staging area (discarding unstaged changes). Which command does this?
Question 22
What is the 'Index' in Git terminology?
Question 23
You have a file `data.log` that is tracked. You add `*.log` to `.gitignore`. `git status` still shows changes to `data.log`. Why?
Question 24
Which command allows you to edit the diff of changes manually before staging them, effectively letting you write a patch by hand?
Question 25
You have staged changes to `fileA` and `fileB`. You want to commit `fileA` now but save `fileB` for a later commit. What should you do?
