Git Staging Changes Quiz

Git
0 Passed
0% acceptance

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.

25 Questions
~50 minutes
1

Question 1

What is the primary purpose of the 'Staging Area' (or 'Index') in Git?

A
To store backup copies of files in case of a crash.
B
To act as an intermediate area where you prepare and refine the snapshot for the next commit.
C
To hold files that are being ignored by .gitignore.
D
To automatically sync changes to the remote server.
2

Question 2

You have modified `file.txt`. Which command moves these modifications from your working directory to the staging area?

A
git commit file.txt
B
git stage file.txt
C
git add file.txt
D
git push file.txt
3

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?

A
git restore --staged secret.txt
B
git reset HEAD secret.txt
C
git rm secret.txt
D
git checkout secret.txt
4

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?

A
Your changes have been lost.
B
Your changes are currently in the staging area.
C
Your changes have already been committed.
D
You are looking at the wrong branch.
5

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?

A
git add -i
B
git add --part
C
git add -p
D
git stage --hunk
6

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?

A
git add config.json
B
git rm config.json
C
git add -u
D
All of the above.
7

Question 7

What is the difference between `git add .` and `git add -u`?

A
They are identical.
B
`git add .` stages new files and modifications, while `git add -u` only stages modifications and deletions to already tracked files (ignoring new files).
C
`git add -u` stages untracked files, while `git add .` does not.
D
`git add .` commits the changes immediately.
8

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?

A
git add --force <file>
B
git add --ignore <file>
C
You must remove it from .gitignore first.
D
git commit <file>
9

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?

A
It is overwritten by the new blob.
B
It remains in the database as a 'dangling' blob until garbage collection runs.
C
Git prevents you from staging the same file twice.
D
It is automatically committed.
10

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?

A
It shows the file twice: once as 'Changes to be committed' and once as 'Changes not staged for commit'.
B
It shows only the latest version as staged.
C
It shows only the unstaged changes.
D
It shows a conflict error.
11

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?

A
git show :main.js
B
git cat-file -p main.js
C
git view --staged main.js
D
git checkout -p main.js
12

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?

A
git rm passwords.txt
B
git rm --cached passwords.txt
C
git delete --keep passwords.txt
D
git reset passwords.txt
13

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?

A
y (yes)
B
n (no)
C
s (split)
D
q (quit)
14

Question 14

What does `git diff --cached` do?

A
It shows the difference between the working directory and the stash.
B
It is a synonym for `git diff --staged`.
C
It shows the difference between the local cache and the remote server.
D
It shows changes in ignored files.
15

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?

A
It will record a deletion and a new file creation.
B
It will automatically detect the rename and stage it as `renamed: old.txt -> new.txt`.
C
It will error because the filenames don't match.
D
It will only stage the new file.
16

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?

A
git status --verbose
B
git ls-files --stage
C
git index --list
D
git show-index
17

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?

A
git add --ignore-space
B
git diff -w | git apply --cached
C
git config core.whitespace false
D
You cannot ignore whitespace when staging.
18

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)?

A
Git commits the current working directory state anyway.
B
Git stops and tells you there is 'nothing to commit'.
C
Git opens the editor but saves an empty commit.
D
Git deletes the repository.
19

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?

A
Run `git commit` immediately.
B
Run `git add conflict.txt`.
C
Run `git resolve conflict.txt`.
D
Delete the file.
20

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?

A
git add script.sh
B
git update-index --chmod=+x script.sh
C
Git does not track file permissions.
D
Both A and B can work.
21

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?

A
git restore .
B
git reset --hard
C
git checkout .
D
Both A and C.
22

Question 22

What is the 'Index' in Git terminology?

A
A list of all commits.
B
Another name for the Staging Area.
C
The remote server.
D
The configuration file.
23

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?

A
You need to restart Git.
B
Git ignores files only if they are untracked. If a file is already tracked, `.gitignore` has no effect on it.
C
The `.gitignore` file is in the wrong format.
D
You need to run `git add .gitignore` first.
24

Question 24

Which command allows you to edit the diff of changes manually before staging them, effectively letting you write a patch by hand?

A
git add -e
B
git add --manual
C
git commit --edit
D
git diff --edit
25

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?

A
git commit fileA
B
git restore --staged fileB
C
git reset
D
Both A and B are valid approaches.