Module Review: Advanced Git
Test your knowledge of Advanced Git concepts including interactive rebase, history rewriting, recovering lost commits with the reflog, and binary search debugging with bisect. Use the flashcards and cheat sheet below to review key commands and principles.
Key Takeaways
- Interactive Rebase (
git rebase -i) is the ultimate tool for cleaning up local history. You can squash, reword, drop, and reorder commits. - Never Rebase Public History. If you have pushed it, do not rebase it. Use
git revertinstead. - Reset moves the HEAD pointer.
--soft: Keeps changes staged.--mixed: Keeps changes unstaged (working directory).--hard: Destroys changes.
- Reflog is your safety net. It tracks every movement of HEAD, allowing you to recover “lost” commits and deleted branches.
- Bisect uses binary search to find bugs in a large commit history efficiently (
O(log N)).
Interactive Flashcards
Which command allows you to combine multiple commits into one?
</div>
<div class="flashcard-back" markdown="1">
git rebase -i (using “squash” or “fixup”)
</div>
</div>
What is the difference between reset and revert?
</div>
<div class="flashcard-back" markdown="1">
reset rewrites history (unsafe for public). revert adds a new commit to undo changes (safe for public).
</div>
</div>
You accidentally ran git reset --hard. How do you recover?
</div>
<div class="flashcard-back" markdown="1">
Use git reflog to find the commit hash before the reset, then reset to it.
</div>
</div>
Which reset mode keeps your changes in the Staging Area?
</div>
<div class="flashcard-back" markdown="1">
--soft
</div>
</div>
How do you automate finding a bug with a script?
</div>
<div class="flashcard-back" markdown="1">
git bisect run <script>
</div>
</div>
What does git commit --amend do?
</div>
<div class="flashcard-back" markdown="1">
It modifies the most recent commit (changing the message or adding files). It changes the SHA-1 hash!
</div>
</div>
| Command | Description |
|---|---|
| Rebasing | |
git rebase -i HEAD~n |
Start interactive rebase for last n commits. |
git rebase --continue |
Continue rebase after resolving conflicts. |
git rebase --abort |
Stop rebase and return to original state. |
| Rewriting | |
git commit --amend |
Edit the last commit message/content. |
git reset --soft HEAD~1 |
Undo commit, keep changes staged. |
git reset --mixed HEAD~1 |
Undo commit, keep changes unstaged. |
git reset --hard HEAD~1 |
Undo commit, destroy changes. |
git revert <commit> |
Create a new commit that undoes changes. |
| Recovery | |
git reflog |
Show log of HEAD movements. |
git reset --hard HEAD@{n} |
Move HEAD to a specific point in reflog. |
| Debugging | |
git bisect start |
Start binary search. |
git bisect good <ref> |
Mark commit as good. |
git bisect bad <ref> |
Mark commit as bad. |
git bisect reset |
Exit bisect mode. |