Bitzu

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

Single choice

Which git reset mode, the default, resets the index but leaves your working tree files untouched?

  1. --soft
  2. --mixed
  3. --hard
  4. --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.

Select all that apply

Which statements about undoing changes are true?

  1. git revert records a new commit that undoes an earlier one
  2. git reset --hard overwrites files in the working tree
  3. git reset --soft leaves both the index and working tree unchanged
  4. git revert rewrites the existing commit in place
  5. 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.

True or false

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.

Download on the App StoreGet it on Google Play

More AZ-400 topics in this module