Skip to content

Instantly share code, notes, and snippets.

@ToanPV90
Created February 23, 2019 04:07
Show Gist options
  • Save ToanPV90/52e151c6916a3d4ec175b6b81c9d2ee0 to your computer and use it in GitHub Desktop.
Save ToanPV90/52e151c6916a3d4ec175b6b81c9d2ee0 to your computer and use it in GitHub Desktop.
unstage files with git
# new file: to-be-added
# modified: to-be-modified
# deleted: to-be-removed
#
me$ git reset -q HEAD to-be-added
# ok
me$ git reset -q HEAD to-be-modified
# ok
me$ git reset -q HEAD to-be-removed
# ok
# or alternatively:
me$ git reset -q HEAD to-be-added to-be-removed to-be-modified
# ok
me$ git status
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: to-be-modified
# deleted: to-be-removed
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# to-be-added
no changes added to commit (use "git add" and/or "git commit -a")
git reset HEAD (without -q) gives a warning about the modified file and its exit code is 1 which will be considered as an error in a script.
Edit: git checkout HEAD to-be-modified to-be-removed also works for unstaging, but removes the change completely from the workspace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment