Git 提交修改內容和查看被修改的內容


我們將倉庫里的readme.txt文件修改一下,改成如下內容:

Git is a distributed version control system
Git is free software.

運行git status命令查看一下結果:

$ 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: readme.txt

no changes added to commit (use "git add" and/or "git commit -a")

git status命令可以讓我們時刻的掌握倉庫的當前狀態,上面的信息告訴我們,readme.txt被修改過了,但是還沒有准備提交修改

Git雖然告訴我們readme.txt被修改了,但是如果能看到修改了什么內容就是最好的了,好比你忘記了上次怎么修改的readme.txt,

這時候你就要用 git diff這個命令看看:

$ git diff readme.txt
diff --git a/readme.txt b/readme.txt
index 58998b5..9c3f69a 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-Git is a version control system
+Git is a distributed version control system
Git is free software.
\ No newline at end of file

git diff 顧名思義就是查看difference,顯示格式正是Unix通用的diff格式,可以從上面的輸出信息看出,第一行添加了一個"distributed"單詞。

知道了對readme.txt作了什么修改后,再把它提交到倉庫就放心多了,提交修改和提交新文件是一樣的,分add和commit兩步:

LV@LV-PC MINGW32 /c/gitRespository (master)
$ git add readme.txt            //添加修改的文件

LV@LV-PC MINGW32 /c/gitRespository (master)
$ git status                 //當前倉庫的狀態:將要被提交的修改包括readme.txt
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: readme.txt


LV@LV-PC MINGW32 /c/gitRespository (master)
$ git commit -m "modify the readme.txt commit"  //提交
[master 4b1d71b] modify the readme.txt commit
1 file changed, 1 insertion(+), 1 deletion(-)

LV@LV-PC MINGW32 /c/gitRespository (master)
$ git status              //當前倉庫狀態:沒有需要提交的修改,工作目錄是干凈的
On branch master
nothing to commit, working directory clean


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM