Git Git Advanced Features 2 β Questions and Answers
Question 1: What does interactive rebase (`git rebase -i`) allow you to do?
- Rebase while resolving conflicts interactively
- Reorder, squash, edit, or drop commits before replaying them (Correct answer)
- Merge branches interactively
- Choose which files to rebase
Correct answer: Reorder, squash, edit, or drop commits before replaying them
Interactive rebase opens an editor listing the commits to be replayed, letting you reorder, squash, split, edit, or drop individual commits.
Question 2: How do you create a stash that includes untracked files?
- git stash -a
- git stash -u
- git stash --include-untracked
- Both B and C are correct (Correct answer)
Correct answer: Both B and C are correct
Both `git stash -u` and `git stash --include-untracked` stash untracked files in addition to tracked modified files.
Question 3: What is `git worktree` used for?
- Managing submodule directories
- Checking out multiple branches simultaneously in separate directories (Correct answer)
- Creating backup copies of the repository
- Managing large binary files
Correct answer: Checking out multiple branches simultaneously in separate directories
Git worktrees allow you to check out additional branches of the same repository into separate directories simultaneously, without needing multiple clones.
Question 4: What is the purpose of `git gc` (garbage collection)?
- Removes all untracked files from the working directory
- Cleans up unnecessary objects and optimizes the local repository's pack files (Correct answer)
- Deletes all remote-tracking branches
- Removes all stashes
Correct answer: Cleans up unnecessary objects and optimizes the local repository's pack files
The `git gc` command removes loose objects that are no longer reachable, packs existing loose objects, and prunes expired reflog entries to optimize the repository.
Question 5: What does `git archive` do?
- Compresses the `.git` directory
- Exports a snapshot of the repository tree as a tar or zip archive without Git metadata (Correct answer)
- Creates a backup of all branches
- Archives old commits to save disk space
Correct answer: Exports a snapshot of the repository tree as a tar or zip archive without Git metadata
The `git archive` command creates a compressed archive of the files in a tree object (commit, tag, or branch), excluding the `.git` directory.
Question 6: How does `git revert` differ from `git reset` when undoing changes?
- They are identical in behavior
- revert creates a new commit that undoes changes; reset moves the branch pointer back (Correct answer)
- reset creates a new commit; revert moves the branch pointer
- revert only works on files; reset works on commits
Correct answer: revert creates a new commit that undoes changes; reset moves the branch pointer back
The `git revert` command creates a new commit that undoes the changes of a previous commit, preserving history, while `git reset` moves the branch pointer and can rewrite history.
What does interactive rebase (`git rebase -i`) allow you to do?