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

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

    I'm surprised noone mentioned the git reflog (http://git-scm.com/docs/git-reflog):

    # git reflog
    
    # git reset HEAD@{1}
    

    The reflog is a git history that not only tracks the changes to the repo, but also tracks the user actions (Eg. pull, checkout to different branch, etc) and allows to undo those actions. So instead of unstaging the file that was mistakingly staged, where you can revert to the point where you didn't stage the files.

    This is similar to git reset HEAD but in certain cases may be more granular.

    Sorry - not really answering your question, but just pointing yet another way to unstage files that I use quite often (I for one like answers by Ryan Stewart and waldyrious very much.) ;) I hope it helps.

提交回复
热议问题