本Git系列內容更多是基于廖雪峰老師的Git教程的個人筆記、總結和擴展,如有錯誤,請多多指正。
我們現在可以修改一下上一節創建的1.txt中的內容,添加一行字符
hello git
hello world
保存后,可以在 Git bash 中 輸入命令
$ git status
這條命令的意思是顯示當前倉庫的狀態,回車之后會輸出以下字符
On branch 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: 1.txt
no changes added to commit (use "git add" and/or "git commit -a")
輸出顯示當前倉庫有個文件進行了修改但沒有提交,如果你想查看這個文件與分支中的文件版本有什么區別,就可以通過git diff
命令來查看修改內容 (需要保證文件文字編碼正確)
$ git diff
回車之后會輸出以下字符
$ git diff
diff --git a/1.txt b/1.txt
index 8d0e412..a5421d4 100644
--- a/1.txt
+++ b/1.txt
@@ -1 +1,2 @@
hello git
+hello world
\ No newline at end of file
通過輸出的內容我們可以得知,我們在1.txt添加了一行 hello world
這時候我們就可以提交修改的文件
$ git add 1.txt
回車之后先不要著急進行下一步,我們可以繼續使用git status
來查看當前的倉庫狀態
$ git status
回車之后會輸出以下字符
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: 1.txt
輸出的內容告訴我們,將要提交的文件包括1.txt,這時候我們就可以放心提交了
$ git commit -m '1.txt_v2.0'
$ git commit -m '1.txt_v2.0'
[master df29370] 1.txt_v2.0
1 file changed, 1 insertion(+)
提交完成之后我們可以再次使用git status
來查看當前的倉庫狀態
$ git status
回車之后輸出以下字符
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
git status
告訴我們,現在工作區是干凈的并且我們沒有需要提交的修改