Git 删除文件
在Git中,删除也是一种修改的操作,我们验证一下,先在工作目录中添加一个新文件test.txt,并且提交:
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
$ git add test.txt
$ git commit -m "测试删除效果"
[master 2f252e8] 测试删除效果
1 file changed, 1 insertion(+)
create mode 100644 test.txt
$ rm test.txt 删除文件或者去工作区里删除也可以
查看一下转态,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 checkout -- <file>..." to discard changes in working directory)
deleted: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
这里分两种情况:
1.一种是情况是删错了,此种情况下,版本库里还有这个文件,我们可以把这个文件恢复到工作区就行了
git checkout -- test.txt
2.第二种情况是,确实想从版本库中的删除该文件。那就用命令git rm删掉,并且commit
LV@LV-PC MINGW32 /c/gitrepository (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
LV@LV-PC MINGW32 /c/gitrepository (master)
$ git rm test.txt
rm 'test.txt'
LV@LV-PC MINGW32 /c/gitrepository (master)
$ git commit -m "remove test.txt"
[master c4d239c] remove test.txt
1 file changed, 1 deletion(-)
delete mode 100644 test.txt
小结:
git rm 命令用于删除一个文件,如果一个文件被提交到版本库,那么你永远不用担心误删了。
但是要小心的是,你只能恢复文件到最新的版本,你会丢失最近一次提交后你修改的内容
Git 删除文件的更多相关文章
- git --删除文件、重命名
修改最后一次提交 git commit --amend -m “” 删除文件:. git rm <需要删除的文件> 只是删除当前工作目录和暂存区的文件,也就是取消跟踪.在下次提交时不纳入版 ...
- git 删除文件/移动文件
1.git rm 删除文件 git restore --file (git老版本:git checkout) git rm --file(本地和管理都已删除) git rm --cached file ...
- git 删除文件 、只删除远程仓库文件、更换远程仓库
一.删除文件 1.克隆远程仓库到本地库. 例如使用ssh方法: git clone git@github.com:xxx/xxx.git 2.对需要删除的文件.文件夹进行如下操作: git rm te ...
- git删除文件需要注意的事项
当commit提交一个文件a到本地仓库中,然后又git rm a 删除这个文件(),再执行git push后,同样会把a文件push到远程仓库.并且这个时候执行git pull并不会从远程仓库拉取a文 ...
- Git删除文件操作
使用Git删除文件需要使用Git rm命令来实现,最后git commit 需要注意的是直接rm命令删除后是不可以的,可以用git status 命令尝试一下,效果如图下(创建了test文件,演示了g ...
- git删除文件夹
git rm 要删除的文件夹 -r -f git commit -m 'del config' git push 使用场景,删除test文件夹,本来在码云上,正常的文件夹右击会出现 ...
- Git删除文件
Git基础 Git有三大区(工作区.暂存区.版本库),文件有三个状态(untracked.unstaged.uncommited). (1)打开项目文件夹,除了隐藏的.git文件夹,其他项目文件位于的 ...
- git 常用命令(含删除文件)
git 常用命令(含删除文件) Git常用操作命令收集: 1) 远程仓库相关命令 检出仓库:$ git clone git://github.com/jquery/jquery.git 查看远程仓库: ...
- git删除远程仓库文件
1 首先将远程代码pull到本地,保持本地仓库跟远端仓库同步 git pull git@github.com:lanleilin/lanGallery.git//使用SSH的方式 2 然后使用git ...
随机推荐
- MAC下安装automake autoconf工具
I noticed today that while Mac OS 10.6 (specifically, 10.6.2) comes with automake and autoconf, the ...
- Hive中频繁报警的问题
在使用Hive的过程中,是不是会在shell中报一堆警告,虽然说不影响正常使用,但是看着很烦人,而且指不定会影响数据的准确性和运行的稳定性. 警告的内容如下: Tue Aug :: CST WARN: ...
- 寻找中位数v1.0
题目内容: 编写一个函数返回三个整数中的中间数.函数原型为: int mid(int a, int b, int c); 函数功能是返回a,b,c三数中大小位于中间的那个数. 输入格式: " ...
- https请求时出错:Could not establish trust relationship for the SSL/TLS secure channel
当我在用NET命名空间下获取URL的时候,提示如下错误: The underlying connection was closed: Could not establish trust relatio ...
- Struts2第二天
Struts2第二天 昨天: 1.Action的编写方式:实现Action接口.继承ActionSupport.自定义pojo作为action 2.action调用方法:默认的execute.meth ...
- hdu1020
#include <stdio.h> int main(void){ int n,i,c; char txt[10001]; scanf("%d", &n); ...
- 第八十九节,html5+css3pc端固定布局,热门旅游取,标题介绍区,旅游项目区
html5+css3pc端固定布局,热门旅游取,标题介绍区,旅游项目区 样式: html代码: <!--主体--> <section class="zhu-ti" ...
- tomcat Server.xml Context配置
有时候需要在tomcat里面做特殊的配置,来进行访问: 例如你的程序 名字是hello端口是80 这时候你要访问你的程序 就要用 localhost/hello 来访问了. 但是怎么直接用 loca ...
- C#连接sqlserver数据库
// 混合登录 写法1:Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPas ...
- 大数加法(STL list)
#include<iostream> #include<list> #include<string> using namespace std; int main() ...