5:git对文件的删除处理

git对文件删除处理

1:查看有几个文件

$ ls
test.txt

2:新建一个文件

vi a.txt

同时输入内容:我是用来删除测试的文件

3:查看有几个文件

$ ls
a.txt  test.txt	

4:查看文件状态信息

$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        a.txt

nothing added to commit but untracked files present (use "git add" to track)

4:添加到暂存区

git add .

5:查看文件状态信息

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   a.txt

6:添加到版本库

$ git commit -m "新增文件"
[master 5434777] 新增文件
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a.txt

7:查看文件状态信息

$ git status
On branch master
nothing to commit, working directory clean

8:物理删除文件

rm a.txt

9:查看有几个文件

$ ls
test.txt

10:查看文件状态:

$ 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:    a.txt

no changes added to commit (use "git add" and/or "git commit -a")

11:恢复删除文件

$ git checkout -- a.txt

12:查看有几个文件

$ ls
a.txt  test.txt	

13:查看文件状态信息

$ git status
On branch master
nothing to commit, working directory clean

因为暂存区和分支都保存有该文件信息,工作区恢复后,代码一致,所以工作区是干净的

14:继续删除

rm a.txt

15:把删除状态提交到暂存区

$ git rm a.txt
rm 'a.txt'

16:查看文件状态信息

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    a.txt

17:恢复删除到工作区

$ git reset HEAD a.txt
Unstaged changes after reset:
D       a.txt

18:查看状态

$ 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:    a.txt

no changes added to commit (use "git add" and/or "git commit -a")

19:把删除文件从工作区恢复

$ git checkout -- a.txt

20:查看文件状态信息

$ git status
On branch master
nothing to commit, working directory clean

21:查看文件

$ ls
a.txt  test.txt

22:继续删除

rm a.txt
$ Ggit rm a.txt
$ git commit -m "删除文件"
[master ae24874] 删除文件
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 a.txt

23:继续恢复

git log//查找commit_id
$ git reset --hard 5434777028014d595851eac9ecedbb571800e07a
HEAD is now at 5434777 新增文件
$ ls
a.txt  test.txt

删除的文件又回来了

posted on 2016-05-05 17:57  借个火点烟  阅读(157)  评论(0编辑  收藏  举报