git rm操作命令

如何使用git删除相关文件呢?

git rm为git删除命令,常用格式如下

git rm -r #从git和本地文件中删除某个文件或某个文件夹

git rm #从git和本地文件中删除某个文件

git rm –cached #把文件从git仓库中删除,但,文件仍然保存在当前文件目录中

1.删除文件目录a及其目录下的文件a.txt

1
2
3
4
5
    ksnowlv@ksnowlvdeMacBook-Pro~/Music/gittest$git rm -r a
    rm 'a/d.txt'
    ksnowlv@ksnowlvdeMacBook-Pro~/Music/gittest$ls
    a.text b.txt  c.txt
    

2.删除文件c.txt

1
2
3
4
    ksnowlv@ksnowlvdeMacBook-Pro~/Music/gittest$git rm c.txt
    rm 'c.txt'
    ksnowlv@ksnowlvdeMacBook-Pro~/Music/gittest$ls
    a

3.删除git仓库中的文件目录a及其目录下的文件a.txt,但是本地目录中仍然保留。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
    ksnowlv@ksnowlvdeMacBook-Pro~/Music/gittest$git rm -r --cache a
    rm 'a/a.txt'
    ksnowlv@ksnowlvdeMacBook-Pro~/Music/gittest$git status
    On branch master
    Changes to be committed:
    (use "git reset HEAD <file>..." to unstage)

	deleted:    b.txt

    Untracked files:
    (use "git add <file>..." to include in what will be committed)
	a/