Web Development Version Control 2 — Questions and Answers
Question 1: What does `git rebase` do compared to `git merge`?
- Rebase rewrites commit history by replaying commits onto a new base (Correct answer)
- Rebase creates a merge commit that combines two branches
- Rebase deletes the source branch after combining
- Rebase only works on local branches, not remote ones
Correct answer: Rebase rewrites commit history by replaying commits onto a new base
Git rebase replays commits from one branch onto another, creating a linear history without a merge commit.
Question 2: Which command shows the commit history as a graph in the terminal?
- git log --graph --oneline (Correct answer)
- git show --tree
- git branch --visual
- git history --graph
Correct answer: git log --graph --oneline
`git log --graph --oneline` displays an ASCII graph of the branch and merge history alongside condensed commit info.
Question 3: What is a 'detached HEAD' state in Git?
- HEAD points directly to a commit instead of a branch (Correct answer)
- The HEAD file is missing or corrupted
- HEAD is pointing to a deleted remote branch
- The repository has no commits yet
Correct answer: HEAD points directly to a commit instead of a branch
A detached HEAD occurs when HEAD points to a specific commit SHA rather than a branch name.
Question 4: What does `git cherry-pick <commit-hash>` do?
- Applies the changes from a specific commit onto the current branch (Correct answer)
- Selects the best commit from a list of candidates
- Copies a branch to a new location
- Removes a commit from the history
Correct answer: Applies the changes from a specific commit onto the current branch
Cherry-pick applies the diff introduced by a specific commit onto the currently checked-out branch.
Question 5: In Git, what is the purpose of `.gitignore`?
- Specifies intentionally untracked files that Git should ignore (Correct answer)
- Lists files that are read-only in the repository
- Defines which users cannot access certain files
- Prevents specific files from being committed to remote
Correct answer: Specifies intentionally untracked files that Git should ignore
`.gitignore` lists patterns of files and directories that Git should not track or include in commits.
Question 6: What happens when you run `git fetch` without `git merge`?
- Remote changes are downloaded but your working directory is not updated (Correct answer)
- Remote and local branches are automatically synchronized
- Local commits are pushed to the remote
- The local repository is reset to match the remote
Correct answer: Remote changes are downloaded but your working directory is not updated
`git fetch` retrieves remote changes into your local repository's remote-tracking branches without altering your working files.
Question 7: Which Git command is used to temporarily save uncommitted changes without committing them?
- git stash (Correct answer)
- git save
- git hold
- git cache
Correct answer: git stash
`git stash` shelves your working directory changes so you can switch contexts and reapply them later.
What does `git rebase` do compared to `git merge`?