Git 暂存修改文件 取消暂存

序: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 ..." to update what will be committed)

  (use "git checkout -- ..." 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 ..." 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 ..." 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 ..." to update what will be committed)

  (use "git checkout -- ..." 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



你可能感兴趣的:(工具)