git unstage

Why are there two ways to unstage a file in Git?

git rm --cached <filePath> does not unstage a file, it actually stages the removal of the file(s) from the repo (assuming it was already committed before) but leaves the file in your working tree (leaving you with an untracked file).

git reset -- <filePath> will unstage any staged changes for the given file(s).

That said, if you used git rm --cached on a new file that is staged, it would basically look like you had just unstaged it since it had never been committed before.

 

Remove a file from a Git repository without deleting it from the local filesystem

From the man file:

When --cached is given, the staged content has to match either the tip of the branch or the file on disk, allowing the file to be removed from just the index.

So, for a single file:

git rm --cached mylogfile.log

and for a single directory:

git rm --cached -r mydirectory

 

-cached

Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.

 

 

 

 

 

 

posted @ 2018-08-31 11:22  ChuckLu  阅读(2144)  评论(0编辑  收藏  举报