前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Git 暂存修改文件 取消暂存

Git 暂存修改文件 取消暂存

作者头像
星宇大前端
发布2019-01-15 15:36:48
2.8K0
发布2019-01-15 15:36:48
举报
文章被收录于专栏:大宇笔记

序:Git 已经用了不少年了,起步用的SourceTree ,所以对命令不是很熟悉,最近换了台电脑,索性不按sourceTree了,总结下命令行。

Git 最经常使用的操作就是:  

工作空间----已修改文件----暂存----提交到本地git---push到远程git

这是一条我们没有特殊需求,没有出现错误和冲突的流程。

1.查看工作空间已修改的文件

git status

example:

zhangyudeiMac:server-psi zhangyu$ 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:   web/Application/Common/Conf/config.php

modified:   web/Application/Mobile/Controller/PurchaseDetailController.class.php

modified:   web/Application/Mobile/View/Purchase/purchaseList.html

modified:   web/Application/Mobile/View/PurchaseDetail/purchaseDetail.html

modified:   web/Public/Scripts/Mobile/PurchaseDetail/PurchaseDetail.js

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

2.上个命令我们就可以看出所有修改过的文件,让后我们应该暂存这些文件。

  * 单文件暂存

git add  "Path(文件路径)"

example:

zhangyudeiMac:server-psi zhangyu$ git  add web/Application/Mobile/Controller/PurchaseDetailController.class.php

  * 暂存全部已修改文件

git add  -u

example:

zhangyudeiMac:server-psi zhangyu$ git add -u

zhangyudeiMac:server-psi zhangyu$ 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:   web/Application/Common/Conf/config.php

modified:   web/Application/Mobile/Controller/PurchaseDetailController.class.php

modified:   web/Application/Mobile/View/Purchase/purchaseList.html

modified:   web/Application/Mobile/View/PurchaseDetail/purchaseDetail.html

modified:   web/Public/Scripts/Mobile/PurchaseDetail/PurchaseDetail.js

3.暂存的文件都是要为提交做准备的文件,如果我们有些文件已经暂存了,我们想还原到非暂存怎么办。

git reset  "Path(文件路径)"

example:

zhangyudeiMac:server-psi zhangyu$ git reset web/Application/Common/Conf/config.php

Unstaged changes after reset:

M web/Application/Common/Conf/config.php

zhangyudeiMac:server-psi zhangyu$ 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:   web/Application/Mobile/Controller/PurchaseDetailController.class.php

modified:   web/Application/Mobile/View/Purchase/purchaseList.html

modified:   web/Application/Mobile/View/PurchaseDetail/purchaseDetail.html

modified:   web/Public/Scripts/Mobile/PurchaseDetail/PurchaseDetail.js

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:   web/Application/Common/Conf/config.php

4.最后一步是提交到本地git和push到远程git,估计都会还是贴上吧。

zhangyudeiMac:server-psi zhangyu$ git commit -m "bangdingwuliuadd"

zhangyudeiMac:server-psi zhangyu$ git push

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018年01月18日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档