Why use 'git rm' to remove a file instead of 'rm'?

前端 未结 7 1154
不思量自难忘°
不思量自难忘° 2020-12-02 04:39

On SVN, removing something from the filesystem directly (rather than using svn) created a load of headaches.

I haven\'t found this to be an issue when using gi

7条回答
  •  一个人的身影
    2020-12-02 05:08

    Remove files from the index, or from the working tree and the index. git rm will not remove a file from just your working directory.

    Here's how you might delete a file using rm -f and then remove it from your index with git rm

    $ rm -f index.html
    $ git status -s
     D index.html
    $ git rm index.html
    rm 'index.html'
    $ git status -s
    D  index.html
    

    However you can do this all in one go with just git rm

    $ git status -s
    $ git rm index.html
    rm 'index.html'
    $ ls
    lib vendor
    $ git status -s
    D  index.html
    

提交回复
热议问题