下面我們就來(lái)討論一下文件的修改和提交,其實(shí)git 跟蹤的非文件而是文件的修改,新增文件、刪除文件、文件增加或刪除行都是屬于文件的修改
現(xiàn)在我們先來(lái)編輯一個(gè)文件
vim test.txt
然后隨便添加一些內(nèi)容
bogon:lishuangshuang shuang$ vim test.txt
bogon:lishuangshuang shuang$ cat test.txt
ceshi wenjian
然后我們通過(guò)git status 查看一下文件的狀態(tài)
bogon:lishuangshuang shuang$ 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: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
然后,添加:
$ git add readme.txt
提交后,用 git diff HEAD -- test.txt命令可以查看工作區(qū)和版本庫(kù)里面最新版本的區(qū)別
bogon:lishuangshuang shuang$ git diff HEAD -- test.txt
diff --git a/test.txt b/test.txt
index 58c9bdf..f28a8ac 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1 @@
-111
+ceshi wenjian
現(xiàn)在可以提交了
$ git commit -m "git tracks changes"[master d4f25b6] git tracks changes 1 file changed, 1 insertion(+)
提交后,再看看狀態(tài):
bogon:lishuangshuang shuang$ 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: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
** Git管理的是修改,當(dāng)你用git add命令后,是將修改被放入暫存區(qū),準(zhǔn)備提交,執(zhí)行g(shù)it commit是負(fù)責(zé)把暫存區(qū)的修改提交了**
最后我們可以 通過(guò)git push 把我們得修改提交到 遠(yuǎn)程版本庫(kù)
也就是說(shuō)我們從修改文件到提交到遠(yuǎn)程分支 需要git add git commit git push 三個(gè)操作