AZ-400 ยท Repository management
Recovering data with Git
reflog, reset (soft/mixed/hard), revert, cherry-pick, restoring deleted branches and files, git bisect, recovering after a bad merge or force push.
Key points
- git reset moves HEAD: --soft keeps index and working tree, --mixed (default) resets the index but keeps files, --hard overwrites files too.
- git revert: new commit undoing an earlier one; safe on shared branches.
- git cherry-pick: applies one commit onto the current branch.
- git reflog: past HEAD positions, finds lost commits; reset stores the previous tip in ORIG_HEAD.
- git bisect: binary-searches for the commit that introduced a bug.
Source: https://git-scm.com/docs/git-reset
Practice questions
Which git reset mode, the default, resets the index but leaves your working tree files untouched?
- --soft
- --mixed
- --hard
- --keep-index
Show answer
Answer: B. --mixed
--mixed is the default: HEAD moves and the index is reset, but files stay. --soft also keeps the index, and --hard overwrites files.
Which statements about undoing changes are true?
- git revert records a new commit that undoes an earlier one
- git reset --hard overwrites files in the working tree
- git reset --soft leaves both the index and working tree unchanged
- git revert rewrites the existing commit in place
- git reset --mixed deletes modified files from disk
Show answer
Answer: A. git revert records a new commit that undoes an earlier one, B. git reset --hard overwrites files in the working tree, C. git reset --soft leaves both the index and working tree unchanged
Revert records a new undoing commit, --hard overwrites working files, and --soft keeps index and working tree. Revert does not rewrite history, and --mixed does not delete working files.
git reset --soft HEAD~1 throws away the changes of the last commit from your working tree.
Show answer
Answer: False
False. --soft only moves HEAD back; the index and working tree stay as they were, so the changes remain staged and ready to recommit.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
