>_ IzzyLab

Hands-on task

This task is step 3 of the course “Everyday Git”

Unstage a file while keeping the edits

easy~2 min

In the repository /root/repo the file file.txt has been modified (it now says modified) and is already staged (git add). Unstage it so that nothing is left in the staging area, but the edits themselves in the working tree are preserved (the content of file.txt must stay modified).

What you'll practise:
  • git
  • git reset
  • --mixed
  • unstage
  • index

Topic breakdown

Unstaging a file is the reverse operation to git add. It's done by git reset in its default mode (--mixed): it resets the index to the last commit but doesn't touch the working tree, so the edits to the file are preserved. You can reset either the whole index or a specific file; the --hard mode is inappropriate here — it would wipe out the changes.

What's checked

  1. index is empty
  2. edits preserved

What it looks like