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

后端 未结 12 1858
刺人心
刺人心 2020-11-27 23:48

Sometimes git suggests git rm --cached to unstage a file, sometimes git reset HEAD file. When should I use which?

EDIT:

D:\         


        
12条回答
  •  执笔经年
    2020-11-28 00:40

    git rm --cached 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 -- 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.

    Update git 2.24
    In this newer version of git you can use git restore --staged instead of git reset. See git docs.

提交回复
热议问题