關於git diff操作及其引數例項講解

2022-09-23 17:21:11 字數 3281 閱讀 5551

先做乙個實驗:

chia@edogawachia-sphinx:~/mygit$ cat readme.txt

this is a readme file

created by e.chia 2018/02/06

modified by e.chia 1st time

chia@edogawachia-sphinx:~/mygit$ git status

位於分支 master

無檔案要提交,乾淨的工作區

chia@edogawachia-sphinx:~/mygit$ sudo vim readme.txt

chia@edogawachia-sphinx:~/mygit$ cat readme.txt

this is a readme file

created by e.chia 2018/02/06

modified by e.chia 1st time

add this to show staged version

chia@edogawachia-sphinx:~/mygit$ sudo git add 'readme.txt'

chia@edogawachia-sphinx:~/mygit$ git status

位於分支 master

要提交的變更:

(使用 "git reset head 檔案》..." 以取消暫存)

修改: readme.txt

chia@edogawachia-sphinx:~/mygit$ sudo vim readme.txt

chia@edogawachia-sphinx:~/mygit$ cat readme.txt

this is a readme file

created by e.chia 2018/02/06

modified by e.chia 1st time

add this to show staged version

add this to show working directory version這樣三個區域的版本都不一樣了,branch中的最短,stage暫存區的有一句add this to show staged version,工作區的多一句 add this to show working directory version。

下面測試各種 diff 的用法:

chia@edogawachia-sphinx:~/mygit$ git diff

diff --git a/readme.txt b/readme.txt

index 3e42036..e24b3e0 100644

--- a/readme.txt

+++ b/readme.txt

@@ -2,3 +2,4 @@ this is a readme file

created by e.chia 2018/02/06

modified by e.chia 1st time

add this to show staged version

+add this to show working directory version

chia@edogawachia-sphinx:~/mygit$ git diff --cached

diff --git a/readme.txt b/readme.txt

index d995350..3e42036 100644

--- a/readme.txt

+++ b/readme.txt

@@ -1,3 +1,4 @@

this is a readme file

created by e.chia 2018/02/06

modified by e.chia 1st time

+add this to show staged version

chia@edogawachia-sphinx:~/mygit$ git diff --staged

diff --git a/readme.txt b/readme.txt

index d995350..3e42036 100644

--- a/readme.txt

+++ b/readme.txt

@@ -1,3 +1,4 @@

this is a readme file

created by e.chia 2018/02/06

modified by e.chia 1st time

+add this to show staged version

chia@edogawachia-sphinx:~/mygit$ git diff head

diff --git a/readme.txt b/readme.txt

index d995350..e24b3e0 100644

--- a/readme.txt

+++ b/readme.txt

@@ -1,3 +1,5 @@

this is a readme file

created by e.chia 2018/02/06

modified by e.chia 1st time

+add this to show staged version

+add this to show working directory version

chia@edogawachia-sphinx:~/mygit$ git diff head -- readme.txt

diff --git a/readme.txt b/readme.txt

index d995350..e24b3e0 100644

--- a/readme.txt

+++ b/readme.txt

@@ -1,3 +1,5 @@

this is a readme file

created by e.chia 2018/02/06

modified by e.chia 1st time

+add this to show staged version

+add this to show working directory version可以看到,git diff 比較工作區和暫存區,git diff –cache (或者–staged)比較版本和暫存區,git diff head – filename 比較branch上的head指向的版本與工作區的區別(這裡的head可以是任意指標,即用雜湊值表示的 commit id ,或者head~等)。這樣三者中的任意兩者都可以比較了。

2018-02-07 16:25:46

關於execlp 函式及其引數問題

在 unix環境高階程式設計 一書中,講到exec函式及其使用,其中有乙個例子,簡單來說就是這樣 execlp ls ls al char 0 其輸出結果就跟我們在終端裡輸入ls命令得到的結果一樣。在說疑問之前,先看函式的定義 int execlp const char file,const cha...

關於記憶體及其引數和插槽型別

一 記憶體的分類 1 sdram synchronous dynamic random access memory,同步動態隨機儲存器。同步是指 memory工作需要同步時鐘,內部的命令的傳送與資料的傳輸都以它為基準 動態是指儲存陣列需要不斷的重新整理來保證資料不丟失 隨機是指資料不是線性依次儲存,...

Git 關於git diff 是和誰對比的問題

git diff cached 是暫存區 stage 和 版本庫的比較 stage或cache與雖說是暫存區,緩衝區,但commit並不是像想像那樣把這個區清空,估計只是打個同步的標誌,內容還在。git add是把工作區的更新提交到暫存區,git commit是把暫存區內容更新到倉庫。所以經過add...