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

后端 未结 12 1844
刺人心
刺人心 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:36

    Let's say you stage a whole directory via git add , but you want to exclude a file from the staged list (i.e. the list that generates when running git status) and keep the modifications within the excluded file (you were working on something and it's not ready for commit, but you don't want to lose your work...). You could simply use:

    git reset

    When you run git status, you will see that whatever file(s) you reset are unstaged and the rest of the files you added are still in the staged list.

提交回复
热议问题