Git 暫存修改檔案 取消暫存

ZY_FlyWay發表於2018-01-18

序: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



相關文章