码迷,mamicode.com
首页 > 其他好文 > 详细

checkout

时间:2017-11-14 14:23:36      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:blog   内容   head   checkout   tor   filename   readme.md   date   str   

checkout命令经常被用来切换分支,但是git checkout -- fileName 还可以将没有提交到暂存区中的修改删除,恢复未修改的状态(但是对于新建的文件无法恢复到新建之前)

现在有两个文件,README.md 和 README2.md,进行修改,并新建文件README3.md,执行git status之后

```
git$ git status

On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   README.md
    modified:   README2.md

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

    README3.md

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

然后执行git add README.md将第一个文件加入到暂存区,执行git status命令如下

```
git$ git add README.md
git$ git status

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

    modified:   README.md

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   README2.md

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

    README3.md
```

现在执行git checkout -- .(.符号表示全部文件)全部恢复工作区修改之前的内容,再执行git status命令如下

```
git$ git checkout -- .
git$ git status

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

    modified:   README.md

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

    README3.md
```

可见 git checkout -- file 可以恢复未被暂存的内容,但是不能恢复被暂存的内容和新建的文件,那么如果想要恢复已经暂存的内容怎么办,那么就需要用到git reset

checkout

标签:blog   内容   head   checkout   tor   filename   readme.md   date   str   

原文地址:http://www.cnblogs.com/xiaohanblog/p/7831776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!