git删除文件

git里删除是一种修改操作

删除文件

先提交一个t2.md文件到git里然后利用rm命令删除没用的文件

$ git add t2.md
$ git commit -m "need to delete"
[master f04f5fc] need to delete
 1 file changed, 1 insertion(+)
 create mode 100644 t2.md
$ rm t2.md

此时查看状态的时候,因为删除文件所以工作区和版本库不一致,git status命令会提示哪些文件被删除

$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    t2.md

no changes added to commit (use "git add" and/or "git commit -a")

确定要删的文件

命令git rm删掉,并且git commit

$ git rm test.md
$ git commit -m "remove test.md"
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    t2.md

no changes added to commit (use "git add" and/or "git commit -a")
误删的文件

文件被误删但是版本库里还有保存,可以把误删的文件恢复到被删前的版本

$ git checkout -- test.md
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值