前面介绍了上传代码的流程,在开发中,很多时候我们可以没有这么顺利,会有很多状况出现,本篇文章就是汇总这些使用:
- 文件修改,但是未执行git add
文件修改,回退
我们更改了test项目下a文件中的内容,在a文件中添加了一个字符串
未执行git add
此时我们发现a的更改有误,需要回到文件更改前。
git checkout a //回到文件更改前 放弃改变
xu:test xiaokai$ vim a //编辑完成后,先按下esc,然后 shift + ":",输入wq保存退出。
xu:test xiaokai$ git status
On branch master
Your branch is up-to-date with 'origin/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: a //red
no changes added to commit (use "git add" and/or "git commit -a")
xu:test xiaokai$
执行了git add
git reset HEAD a
当执行了git add 后,就是已经将更改的内容添加到了暂存区,此时,想将添加的内容从暂存区回退到,未添加时,使用git reset HEAD a.
xu:test xiaokai$ git add a
xu:test xiaokai$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: a //green
xu:test xiaokai$ git reset HEAD a
Unstaged changes after reset:
M a
xu:test xiaokai$ git status
On branch master
Your branch is up-to-date with 'origin/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: a //red
no changes added to commit (use "git add" and/or "git commit -a")