Git Git Advanced Features 1 β Questions and Answers
Question 1: What is the main advantage of `git rebase` over `git merge` for integrating changes?
- Rebase is faster for large repositories
- Rebase produces a cleaner, linear commit history without merge commits (Correct answer)
- Rebase preserves the exact original commit timestamps
- Rebase works on remote branches while merge does not
Correct answer: Rebase produces a cleaner, linear commit history without merge commits
Rebasing replays commits on top of another branch, resulting in a linear history free of merge commits, which is easier to read and bisect.
Question 2: What does `git stash pop` do compared to `git stash apply`?
- pop applies the stash and removes it from the stash list; apply applies it but keeps it (Correct answer)
- pop applies only the latest stash; apply applies all stashes
- They are identical
- pop discards the stash without applying; apply applies it
Correct answer: pop applies the stash and removes it from the stash list; apply applies it but keeps it
The `git stash pop` command applies the most recent stash entry and then drops it from the stash list, while `git stash apply` applies it without removing it.
Question 3: Which command applies a specific commit from another branch onto the current branch?
- git merge <commit-hash>
- git cherry-pick <commit-hash> (Correct answer)
- git apply <commit-hash>
- git patch <commit-hash>
Correct answer: git cherry-pick <commit-hash>
The `git cherry-pick <commit-hash>` command applies the changes introduced by the specified commit onto the current branch as a new commit.
Question 4: What is a Git tag, and how does a lightweight tag differ from an annotated tag?
- Tags mark important commits; lightweight is just a pointer while annotated stores extra metadata like tagger and message (Correct answer)
- Tags are branches that do not move; there is no difference between types
- Lightweight tags expire; annotated tags are permanent
- Lightweight tags are for local use only; annotated tags are for remotes
Correct answer: Tags mark important commits; lightweight is just a pointer while annotated stores extra metadata like tagger and message
A lightweight tag is merely a named reference to a commit, while an annotated tag is a full Git object containing the tagger's name, email, date, and a message.
Question 5: What does `git bisect` help you do?
- Split a commit into two smaller commits
- Binary search through commit history to find the commit that introduced a bug (Correct answer)
- Compare two branches side by side
- Split a repository into two separate repositories
Correct answer: Binary search through commit history to find the commit that introduced a bug
The `git bisect` command automates a binary search through commit history, allowing you to efficiently pinpoint which commit introduced a regression.
Question 6: What is a Git submodule?
- A module in the Git source code
- A pointer to a specific commit in another repository, embedded within a parent repository (Correct answer)
- A branch created for a specific module of an application
- A plugin that extends Git functionality
Correct answer: A pointer to a specific commit in another repository, embedded within a parent repository
A Git submodule is a reference to a specific commit in another Git repository, allowing you to embed one repository inside another at a fixed version.
What is the main advantage of `git rebase` over `git merge` for integrating changes?