您的位置:首页 > 其它

git 多人协作开发的使用(二)---命令使用

2017-05-12 16:34 246 查看
前面介绍了上传代码的流程,在开发中,很多时候我们可以没有这么顺利,会有很多状况出现,本篇文章就是汇总这些使用:

文件修改,但是未执行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")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: