#第一种方法:
#1.先删除暂存区中的文件
[root@git ~/git_test]# git rm --cached a.txt
rm 'a.txt'
[root@git ~/git_test]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: b.txt
# new file: c.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# a.txt
[root@git ~/git_test]# ll
total 0
-rw-r--r-- 1 root root 0 2020-05-11 14:36 a.txt
-rw-r--r-- 1 root root 0 2020-05-11 14:36 b.txt
-rw-r--r-- 1 root root 0 2020-05-11 14:36 c.txt
#2.再删除工作目录中的文件
[root@git ~/git_test]# rm -f a.txt
[root@git ~/git_test]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: b.txt
# new file: c.txt
#
#第二种方法:
#把暂存区和工作目录中的文件一起删除
[root@git ~/git_test]# git rm -f b.txt
rm 'b.txt'
[root@git ~/git_test]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: c.txt
#
[root@git ~/git_test]# ll
total 0
-rw-r--r-- 1 root root 0 2020-05-11 14:36 c.txt
Git删除暂存区的文件和工作目录中的文件
最新推荐文章于 2023-01-31 18:20:44 发布