博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Git删除文件
阅读量:4189 次
发布时间:2019-05-26

本文共 2114 字,大约阅读时间需要 7 分钟。

使用场景

当要在工作区删除一个文件并提交到版本库中时,就需要用到git rm命令了。不同于git add添加或修改一个文件,git rm是删除一个文件,并结合git commit将删除改动提交到版本库中。

 

演示

改动之前工作区

➜  Code git:(master) lltotal 8drwxr-xr-x   5 mymac  staff   160  9  7 08:00 ./drwxr-xr-x+ 64 mymac  staff  2048  9  7 08:36 ../drwxr-xr-x  13 mymac  staff   416  9  7 08:36 .git/drwxr-xr-x   3 mymac  staff    96  8  3 15:29 cliff_demo/-rw-r--r--   1 mymac  staff    21  8 25 18:12 master1.txt

现在创建一个名为 __init__.py 的文件,并将它提交到版本库中。

➜  Code git:(master) touch __init__.py➜  Code git:(master) ✗ lltotal 8drwxr-xr-x   6 mymac  staff   192  9  7 08:38 ./drwxr-xr-x+ 64 mymac  staff  2048  9  7 08:38 ../drwxr-xr-x  13 mymac  staff   416  9  7 08:38 .git/-rw-r--r--   1 mymac  staff     0  9  7 08:38 __init__.pydrwxr-xr-x   3 mymac  staff    96  8  3 15:29 cliff_demo/-rw-r--r--   1 mymac  staff    21  8 25 18:12 master1.txt➜  Code git:(master) ✗ git add __init__.py➜  Code git:(master) ✗ git commit -m "demo create a python file."[master b231ce6] demo create a python file. 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 __init__.py➜  Code git:(master) lltotal 8drwxr-xr-x   6 mymac  staff   192  9  7 08:38 ./drwxr-xr-x+ 64 mymac  staff  2048  9  7 08:38 ../drwxr-xr-x  13 mymac  staff   416  9  7 08:38 .git/-rw-r--r--   1 mymac  staff     0  9  7 08:38 __init__.pydrwxr-xr-x   3 mymac  staff    96  8  3 15:29 cliff_demo/-rw-r--r--   1 mymac  staff    21  8 25 18:12 master1.txt

使用 git rm <file>将版本库中的 __init__.py文件删除

使用git rm 命令后,工作区对应的文件会被删除。

➜  Code git:(master) git rm __init__.pyrm '__init__.py'➜  Code git:(master) ✗ lltotal 8drwxr-xr-x   5 mymac  staff   160  9  7 08:41 ./drwxr-xr-x+ 64 mymac  staff  2048  9  7 08:41 ../drwxr-xr-x  13 mymac  staff   416  9  7 08:41 .git/drwxr-xr-x   3 mymac  staff    96  8  3 15:29 cliff_demo/-rw-r--r--   1 mymac  staff    21  8 25 18:12 master1.txt

 

这时版本库中的文件仍未删除,仅仅只是工作区删除了。我们需要继续使用 git commit 将删除修改提交到版本库中。

➜  Code git:(master) ✗ git commit -m "demo delete python file."[master 45669b1] demo delete python file. 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 __init__.py➜  Code git:(master)

 

至此删除版本库中的一个文件的任务就算完成了。

转载地址:http://bfsoi.baihongyu.com/

你可能感兴趣的文章
常用的算法
查看>>
Mina框架
查看>>
Spring MVC 和 Servlet 一样,都不是线程安全的
查看>>
Java线程:线程的同步与锁
查看>>
Mac、Windows可以互相远程
查看>>
oracle提示 ORA-12154: TNS: 无法解析指定的连接标识符
查看>>
oracle 插入数据时提示没有足够的值
查看>>
Oracle Net Manager的使用及配置
查看>>
镜像文件
查看>>
苹果笔记本桌面下面的工具栏没了怎么调出来
查看>>
CSS原理与CSS经验分享
查看>>
oracle中int与number的区别
查看>>
php不用jsonp也能跨域
查看>>
solr作为一种开源的搜索服务器
查看>>
Pig分析数据过程
查看>>
linux下文件夹的创建、复制、剪切、重命名、清空和删除命令
查看>>
pentaho套件
查看>>
软件产品经理职责
查看>>
Linux下Tomcat的安装配置
查看>>
UI即User Interface
查看>>