删除单个文件
普通情况下,通常可直接在文件管理器中直接把文件删了,或者用rm命令删了
$ rm README.txt
这个时候,工作区是删除了,可版本号库还没有。git status命令会立马告诉你哪些文件被删除了
$ git status
On branch master
Your branch is up-to-date with 'origin/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: README.txt
no changes added to commit (use "git add" and/or "git commit -a")
如今有两个选择,一是确实要从版本号库中删除该文件。那就用命令git rm删掉,而且commit
。而且push
$ git rm README.txt
rm 'README.txt'
$ git commit -m "remove README.txt"
[master d17efd8] remove README.txt
1 file changed, 1 deletion(-)
delete mode 100644 README.txt
$ git push -u origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 210 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
To git@github.com:itmyhome2013/mygithub.git
3c147ee..c01c174 master -> master
Branch master set up to track remote branch master from origin.
还有一种情况是删除了。由于版本号库里还有呢,所以能够把误删的文件恢复到最新版本号
$ git checkout -- README.txt
删除目录
可先直接在文件管理器中把要删除的目录删掉(以WEB-INF目录为例)
$ git add --all
$ git commit -m "remove WEB-INF"
$ git push -u origin master
git add -A(--all):表示把全部tracked文件里被改动过或已删除文件和全部untracted的文件信息加入到索引库。
作者:itmyhome
出处:http://blog.csdn.net/itmyhome1990/article/details/39672913