Lessons · Git · taking it out of the next commit
Taking it out of the next commit
git restore --staged moves a file out of the staging area and leaves the file on disk untouched. Without the flag, the same command overwrites the file instead.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
One flag is the difference between 'not in this commit' and 'that edit is gone', and the two commands are one word apart.
How to think about it
Read the two status columns before and after. Staged is the left one; your working copy is the right.
Worked example
git status --shortM in the left column: staged, ready to commit.
git restore --staged f.txtOut of the staging area. The file itself is not touched.
git status --shortM has moved to the right column: still edited, no longer staged.
cat f.txtedited. Which is the whole point of the flag.
Your turn
Unstage f.txt without changing the file.
git restore f.txt
Try it in a real repository
The trap
Dropping the flag. `git restore f.txt` at this point would replace your edit with the committed version, and there would be nothing to get back.
Practise taking it out of the next commit on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.