Usually, to discard changes to a file you would do:
git checkout -- <file>
What if the change I want to discard is deleting the file? The above line would give an error:
error: pathspec '<file>' did not match any file(s) known to git.
What command will restore that single file without undoing other changes?
bonus point: Also, what if the change I want to discard is adding a file? I would like to know how to unstage that change as well.
Assuming you’re wanting to undo the effects of
git rm <file>orrm <file>followed bygit add -Aor something similar:To undo
git add <file>, the first line above suffices, assuming you haven’t committed yet.