当前位置: 首页 > news >正文

删除⽂件之git

删除⽂件

在 Git 中,删除也是⼀个修改操作,我们实战⼀下, 如果要删除 file5 ⽂件,怎么搞呢?如果你这样做了:

此时,⼯作区和版本库就不⼀致了,要删⽂件,⽬前除了要删⼯作区的⽂件,还要清除版本库的⽂件。

root@hcss-ecs-a74f:~# cd gitcode
root@hcss-ecs-a74f:~/gitcode# ls
file1  file2  file3  file4  file5  ReadMe
root@hcss-ecs-a74f:~/gitcode# rm file5
root@hcss-ecs-a74f:~/gitcode# ls
file1  file2  file3  file4  ReadMe
root@hcss-ecs-a74f:~/gitcode# git add file5
root@hcss-ecs-a74f:~/gitcode# git status
On branch master
Changes to be committed:(use "git restore --staged <file>..." to unstage)deleted:    file5

⼀般⾛到这⾥,有两种可能:

• 确实要从版本库中删除该⽂件

• 不⼩⼼删错了

对第⼆种情况,很明显误删,需要使⽤ git 来进⾏恢复,很简单,我们刚学过(删除也是修改):

hyb@139-159-150-152:~/gitcode$ git checkout -- file5
hyb@139-159-150-152:~/gitcode$ ls
file1 file2 file3 file4 file5 ReadMe

对于第⼀种情况,很明显是没有删完,我们只删除了⼯作区的⽂件。这时就需要使⽤ git rm 将⽂件从暂存区和⼯作区中删除,并且 commit :

hyb@139-159-150-152:~/gitcode$ git rm file5
rm 'file5'
hyb@139-159-150-152:~/gitcode$ git status
On branch master
Changes to be committed:(use "git restore --staged <file>..." to unstage)deleted: file5
hyb@139-159-150-152:~/gitcode$ git commit -m"deleted file5"
[master 5476bde] deleted file51 file changed, 0 insertions(+), 0 deletions(-)delete mode 100644 file5
hyb@139-159-150-152:~/gitcode$ git status
On branch master
nothing to commit, working tree clean

现在,⽂件就从版本库中被删除了.

完整过程如下:

root@hcss-ecs-a74f:~# cd gitcode
root@hcss-ecs-a74f:~/gitcode# ls
file1  file2  file3  file4  file5  ReadMe
root@hcss-ecs-a74f:~/gitcode# rm file5
root@hcss-ecs-a74f:~/gitcode# ls
file1  file2  file3  file4  ReadMe
root@hcss-ecs-a74f:~/gitcode# git add file5
root@hcss-ecs-a74f:~/gitcode# git status
On branch master
Changes to be committed:(use "git restore --staged <file>..." to unstage)deleted:    file5root@hcss-ecs-a74f:~/gitcode# git commit -m "delete file5"
[master 33b3d8d] delete file51 file changed, 0 insertions(+), 0 deletions(-)delete mode 100644 file5
root@hcss-ecs-a74f:~/gitcode# git status
On branch master
nothing to commit, working tree clean
root@hcss-ecs-a74f:~/gitcode# git rm file4
rm 'file4'
root@hcss-ecs-a74f:~/gitcode# git status
On branch master
Changes to be committed:(use "git restore --staged <file>..." to unstage)deleted:    file4root@hcss-ecs-a74f:~/gitcode# git commit -m "delete file4"
[master 94cdba6] delete file41 file changed, 0 insertions(+), 0 deletions(-)delete mode 100644 file4
http://www.dtcms.com/a/363056.html

相关文章:

  • 前端20个高效开发的JS工具函数
  • 《水浒智慧》第二部“英雄是怎么炼成的”(下篇)读书笔记
  • 宋红康 JVM 笔记 Day11|直接内存
  • 怎么用redis lua脚本实现各分布式锁?Redisson各分布式锁怎么实现的?
  • Higress云原生API网关详解 与 Linux版本安装指南
  • lua脚本在redis中如何单步调试?
  • docker 安装 redis 并设置 volumes 并修改 修改密码(二)
  • MATLAB矩阵及其运算(四)矩阵的运算及操作
  • 互联网大厂求职面试记:谢飞机的搞笑答辩
  • Linux为什么不是RTOS
  • 对矩阵行化简操作几何含义的理解
  • 集群无法启动CRS-4124: Oracle High Availability Services startup failed
  • TSMC-1987《Convergence Theory for Fuzzy c-Means: Counterexamples and Repairs》
  • uni-app 实现做练习题(每一题从后端接口请求切换动画记录错题)
  • Nginx的反向代理与正向代理及其location的配置说明
  • 久等啦!Tigshop O2O多门店JAVA/PHP版本即将上线!
  • SpringBoot3 + Netty + Vue3 实现消息推送(最新)
  • B树和B+树,聚簇索引和非聚簇索引
  • 云计算学习100天-第44天-部署邮件服务器
  • vscode炒股插件-韭菜盒子AI版
  • 小白H5制作教程!一分钟学会制作企业招聘H5页面
  • Linux 环境配置 muduo 网络库详细步骤
  • WPF 开发必备技巧:TreeView 自动展开全攻略
  • gbase8s之导出mysql导入gbase8s
  • WebSocket STOMP协议服务端给客户端发送ERROR帧
  • 串口服务器技术详解:2025年行业标准与应用指南
  • 大文件稳定上传:Spring Boot + MinIO 断点续传实践
  • DevOps部署与监控
  • WPF中的DataContext以及常见的绑定方式
  • Zynq开发实践(FPGA之流水线和冻结)