1. What is `git reflog` and when is it indispensable?
Reflog records movements of HEAD and refs (even orphaned). It’s crucial for recovering "lost" commits after resets/rebases or branch deletions.
Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
Git & Version Control · Question Set
Committing, Staging & History — Essentials interview questions for placements and exams.
Questions
14
Included in this set
Subject
Git & Version Control
Explore more sets
Difficulty
Mixed
Level of this set
Go through each question and its explanation. Use this set as a focused practice pack for Git & Version Control.
Reflog records movements of HEAD and refs (even orphaned). It’s crucial for recovering "lost" commits after resets/rebases or branch deletions.
`git restore <path>` replaces the file from HEAD (modern replacement for `checkout --`).
Use `git log --grep "keyword"` to locate by message; then `git show <hash>` (optionally `-p --stat`) to view the diff and metadata.
`-S` signs the commit. Configure with `user.signingkey` and GPG agent beforehand.
This combo visualizes branch tips and relationships succinctly across all refs.
`git add -p` lets you review and stage hunks interactively for granular commits.
Keep subject line ≤50 chars in imperative mood (e.g., "Fix crash on null input"). Add a blank line, then a body explaining what and why (context, impact, links).
Stage the missing change, then amend to rewrite the tip commit (avoid on public history).
`restore --staged` removes from Index only; the file contents remain in the working tree.
`--soft` moves HEAD only (keeps Index/WT), `--mixed` moves HEAD and resets Index (keeps WT), `--hard` resets HEAD, Index, and Working Tree (destructive).
`--staged` (aka `--cached`) shows Index vs HEAD; plain `git diff` shows WT vs Index.
`--fixup <hash>` creates a targeted fix commit labeled for autosquash. Later `rebase -i --autosquash` reorders and squashes fixups onto their intended commits automatically, keeping a tidy history.
`-u` stages tracked file modifications and deletions; it skips new untracked files.
The Index is a middle layer between your working tree and the repository. You choose exactly which changes to include in the next snapshot (commit), enabling partial commits and clean, reviewable history.
For complete preparation, combine this set with full subject-wise practice for Git & Version Control. You can also explore other subjects and sets from the links below.