Sometimes git suggests git rm --cached
to unstage a file, sometimes git reset HEAD file
. When should I use which?
D:\code\gt2>git init
Initialized empty Git repository in D:/code/gt2/.git/
D:\code\gt2>touch a
D:\code\gt2>git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# a
nothing added to commit but untracked files present (use "git add" to track)
D:\code\gt2>git add a
D:\code\gt2>git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: a
#
D:\code\gt2>git commit -m a
[master (root-commit) c271e05] a
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a
D:\code\gt2>touch b
D:\code\gt2>git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# b
nothing added to commit but untracked files present (use "git add" to track)
D:\code\gt2>git add b
D:\code\gt2>git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: b
#
git rm
can both stage a deletion and also unstage an addition) – Carnarvonrm
to undoadd
? How do you thinkrm
should behave? – Ragergit init
there is noHEAD
to reset to. – Pirogrm
implies deletion in a unix context. It is not the opposite of adding to the index. A function to remove files shouldn't be overloaded with functions to change the staging-state. If there are implementation details that make those convenient to combine, that simply points to the lack of a thoughtful layer of abstraction in git, which would make usability clear. – Piranhagit stash
technique. See it in action: https://mcmap.net/q/12971/-git-stash-uncached-how-to-put-away-all-unstaged-changes, full docs: git-scm.com/docs/git-stash. Lastlygit stash drop
will poof away all your magic like nothing happened :) – Cholera