1. You checked out a commit SHA directly. Which is TRUE?
Create a branch (`git switch -c`) if you intend to keep commits.
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
Rewriting History Safely — Reset, Revert, Reflog, Restore 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.
Create a branch (`git switch -c`) if you intend to keep commits.
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.
It refuses to overwrite remote work you haven’t fetched, offering a safety check.
HEAD moves back two commits; index and working tree keep the changes from those commits staged. Useful to reword/squash into a single commit.
`git restore <path>` restores file content in working tree from HEAD (or a commit). `git restore --staged <path>` un-stages changes (like `git reset <path>`). They split file restore from branch switching for clarity.
Working tree = your files on disk; index = staged snapshot for the next commit; HEAD = pointer to the last commit of the current branch. Most history edits move HEAD; file-level fixes move working tree or index.
`--mixed` (default) moves HEAD and resets index to the commit, keeping your working files.
`revert` adds a new commit that negates a past one; safe for shared branches.
Revert creates a new inverse commit, preserving subsequent history.
Use `git reflog` to find the previous HEAD (e.g., `HEAD@{2}`) then `git branch rescue HEAD@{2}` or `git reset --hard <that-id>` to restore the state.
`git restore --staged app/config.yml` (or `git reset app/config.yml`) removes it from the index but leaves file changes on disk.
Fetch updates, then hard-reset branch to the remote tip (tracked files).
Use `git revert --no-commit A^..B` to stage inverse changes for the range, review, then `git commit` once. Or `git revert A^..B` to create multiple revert commits.
`--hard` aligns index and working tree to the target commit; untracked files remain unless cleaned.
Rotate the secret. Use `git filter-repo` (or BFG) to purge the file/paths from all commits, force-push with lease, invalidate caches, and update PRs. Add patterns to `.gitignore` to prevent recurrence.