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 ...
随机推荐
- ZZNU 1163: 在线判题(指针专题)
题目描述 Ignatius is building an Online Judge, now he has worked out all the problems except the Judge S ...
- 通用mapper的使用
通用mapper的使用 导入依赖 <dependency> <groupId>com.github.abel533</groupId> <artifactId ...
- ZOJ 1003 Crashing Balloon
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...
- C#_传单小子
2013/4/13日编写,已经许久不用了,今天又翻出来了,打算继续完善这个小软件,明年将发布出来提供给大家使用.
- javascript apply()和call()
原文链接 http://www.jb51.net/article/30883.htm 想要理解透彻apply()和call() ,还要需要理解this 作用域 局部变量 全局变量 js apply ...
- Python 处理文件
1.从现有文件中获取信息 使用Python中的模块,可以从现有文件中获取信息.使用“os”模块和“stat”模块可以获取文件的基本信息: import os import stat import ti ...
- POJ 2425 A Chess Game#树形SG
http://poj.org/problem?id=2425 #include<iostream> #include<cstdio> #include<cstring&g ...
- xcb编译
sed -i "s/pthread-stubs//" configure && ./configure $XORG_CONFIG \ --enable-xinput ...
- JS 之完美运动框架
完美运动框架是对原来的任意值运动框架的改善和效率的提升,即利用了json对属性进行封装,从而提高效率: window.onload=function(){ var oDiv=document.getE ...
- jquery.cookie.js 的配置
一个轻量级的cookie 插件,可以读取.写入.删除 cookie. jquery.cookie.js 的配置 首先包含jQuery的库文件,在后面包含 jquery.cookie.js 的库文件. ...