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

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

    1.

    D:\code\gt2>git status
    # On branch master
    #
    # Initial commit
    #
    # Changes to be committed:
    #   (use "git rm --cached ..." to unstage)
    #
    #       new file:   a
    

    (use "git rm --cached ..." to unstage)

    • git is a system of pointers

    • you do not have a commit yet to change your pointer to

    • the only way to 'take files out of the bucket being pointed to' is to remove files you told git to watch for changes

    2.

    D:\code\gt2>git commit -m a
    [master (root-commit) c271e05] a
    0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 a
    

    git commit -m a

    • you commited, 'saved'

    3.

    D:\code\gt2>git status
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD ..." to unstage)
    #
    #       new file:   b
    #
    

    (use "git reset HEAD ..." to unstage)

    • you made a commit in your code at this time
    • now you can reset your pointer to your commit 'revert back to last save'

提交回复
热议问题