文件的修改和提交

下面我們就來(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è)操作

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容