Web Development Version Control 3 — Questions and Answers
Question 1: What is the difference between `git reset --soft`, `--mixed`, and `--hard`?
- Soft keeps staged+working changes, mixed unstages them, hard discards all changes (Correct answer)
- Soft discards all changes, mixed keeps staged only, hard keeps everything
- Soft resets the remote, mixed resets local, hard resets both
- They are identical but apply to different file types
Correct answer: Soft keeps staged+working changes, mixed unstages them, hard discards all changes
`--soft` moves HEAD but keeps the index and working tree; `--mixed` also unstages; `--hard` discards all local changes.
Question 2: What is a Git 'tag' primarily used for?
- Marking specific points in history as important, such as version releases (Correct answer)
- Labeling files within a commit
- Categorizing branches by feature type
- Assigning ownership of commits to team members
Correct answer: Marking specific points in history as important, such as version releases
Tags create named references to specific commits, most commonly used to mark release versions like v1.0.0.
Question 3: Which command would you use to see what changes are staged for the next commit?
- git diff --cached (Correct answer)
- git status --staged
- git show --index
- git log --pending
Correct answer: git diff --cached
`git diff --cached` (or `--staged`) shows the difference between the index (staging area) and the last commit.
Question 4: What does a 'fast-forward' merge mean in Git?
- The target branch pointer simply moves forward to the source branch tip, no merge commit needed (Correct answer)
- The merge is processed faster using parallel threads
- All commits are squashed into one before merging
- The source branch is deleted immediately after the merge
Correct answer: The target branch pointer simply moves forward to the source branch tip, no merge commit needed
A fast-forward merge is possible when the target branch has no new commits since the source branch diverged, so no merge commit is created.
Question 5: What does `git blame <file>` show?
- Each line of a file annotated with the commit and author that last modified it (Correct answer)
- A list of contributors who have ever touched the repository
- All commits where the file was deleted and restored
- The file's change history as a unified diff
Correct answer: Each line of a file annotated with the commit and author that last modified it
`git blame` shows line-by-line authorship and commit information for a file, useful for tracking when a line was introduced.
Question 6: In GitHub's pull request workflow, what does 'squash and merge' do?
- Combines all PR commits into a single commit before merging into the base branch (Correct answer)
- Merges the branch without any commits
- Rebases the PR commits on top of the base branch
- Merges only the first and last commit of the PR
Correct answer: Combines all PR commits into a single commit before merging into the base branch
Squash and merge collapses all commits in a pull request into one clean commit on the target branch.
Question 7: What is the purpose of `git bisect`?
- Uses binary search to find the commit that introduced a bug (Correct answer)
- Splits a large commit into two smaller ones
- Compares two commits side by side
- Divides a repository into two separate repositories
Correct answer: Uses binary search to find the commit that introduced a bug
`git bisect` performs a binary search through commit history, marking commits as good or bad to isolate where a regression was introduced.
What is the difference between `git reset --soft`, `--mixed`, and `--hard`?