在上一節中咱們已經成功建立版本庫而且已經添加test.txt
等文件,這一節咱們繼續講解如何進行版本控制.git
首先咱們先查看test.txt
文件有什麼內容吧!bash
# 查看文件內容
$ cat test.txt
git test
git init
git diff
$
複製代碼
接下來模擬正常工做,接着輸入一下內容:ui
# 追加新內容到 test.txt 文件
echo "understand how git control version" >> test.txt
# 查看當前文件內容
$ cat test.txt
git test
git init
git diff
understand how git control version
$
複製代碼
緊接着運行 git status
看一下輸出結果:spa
# 查看文件狀態
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: test.txt
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: test.txt
$
複製代碼
從上述 git status
命令輸出的結果能夠看出,test.txt
已經被修改但還沒提交,可是具體發生了什麼變化卻沒能告訴咱們,若是可以告訴咱們具體修改細節那就行了!版本控制
運行**git diff
**命令能夠實現上述需求code
$ git diff
diff --git a/test.txt b/test.txt
index 729112f..989ce33 100644
--- a/test.txt
+++ b/test.txt
@@ -1,3 +1,4 @@
git test
git init
git diff
+understand how git control version
$
複製代碼
git diff
命令即查看差別(difference),從輸出結果能夠看出咱們在最後一行新增了understand how git control version
文字.rem
經過git status
知道文件發生了改動,git diff
讓咱們看到了改動的細節,如今咱們提交到版本庫就放心多了,還記得上節課如何添加版本庫的命令嗎?string
分兩步操做: git add <file>
和 git commit -m <remark>
it
第一步: git add <file>
io
$ git add test.txt
$
複製代碼
等一下,在執行 git commit
命令以前,咱們再運行 git status
命令查看一下當前倉庫狀態:
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: test.txt
$
複製代碼
此時 git status
命令告訴咱們 test.txt
文件已被修改等待提交,好了,那麼接着第二步的commit吧!
第二步: git commit -m <remark>
# 提交到版本庫並添加備註
$ git commit -m "add understand how git control version"
[master 36f234a] add understand how git control version
1 file changed, 2 insertions(+)
$
複製代碼
提交後,咱們此時再次運行git status
命令查看當前倉庫狀態:
$ git status
On branch master
nothing to commit, working tree clean
$
複製代碼
輸出結果顯示沒有須要提價的改動,工做目錄是乾淨的.
git status
git diff