နားလည်ထားရမယ့် အချက်
`git diff` က context သုံးမျိုးထဲမှာ တစ်မေးခွန်းတည်း ဖြေပါတယ် — အတိအကျ ဘာပြောင်းလဲသွားလဲ၊ ဘယ်နှစ်ချက်ကြား နှိုင်းယှဉ်နေလဲဆိုတာပါ။
| Command | ဘာကို နှိုင်းယှဉ်သလဲ |
|---|---|
| git diff | working directory vs staging area |
| git diff --staged | staging area vs နောက်ဆုံး commit |
| git diff A...B | commit/branch နှစ်ခု တိုက်ရိုက် |
Output format ကတော့ context အားလုံးမှာ တူညီပါတယ်။ ပြောင်းလဲသွားတဲ့ file တစ်ခုစီမှာ header ရှိပြီး `@@ -a,b +c,d @@` hunk marker က line range ကို ပြောပေးပါတယ်။
- `-` line — ယခင်ရှိခဲ့ပြီး ဖယ်ရှားလိုက်တာ
- `+` line — အသစ်ထည့်တာ
- Mark မလုပ်ထားတဲ့ line — ပြောင်းလဲမှုမရှိတဲ့ context
`-` line တစ်ခုနဲ့ ဆင်တူတဲ့ `+` line တစ်ခု ကပ်နေရင် များသောအားဖြင့် line တစ်ခုလုံး ပြန်ရေးလိုက်တာ မဟုတ်ဘဲ စကားလုံးတစ်လုံးပဲ ပြောင်းသွားတာပါ — ကြားထဲက သေးငယ်တဲ့ ကွာခြားချက်ကို ရှာပါ။
THREE THINGS git diff CAN COMPARE
---------------------------------
THREE THINGS git diff CAN COMPARE
------------------------------------
git diff : working dir vs staging area
git diff --staged : staging area vs last commit
git diff main...feature : branch main vs branch featureလက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Unstaged diff ကြည့်ပါ
File ပြင်ပြီး `git diff` run ပါ — header, `@@` hunk marker, `-`/`+` line တွေ ပါလာပါလိမ့်မယ်။
Staged diff ကြည့်ပါ
`git add` ပြီး `git diff --staged` run ပါ — content တူပေမယ့် baseline ပဲ ကွာတယ်။
Branch နှစ်ခု နှိုင်းယှဉ်ပါ
`git diff main...feature` က divergence ကနေ ဘာတွေ ပြောင်းလဲထားလဲ ပြပါတယ်။
အတူတူ စမ်းရေးကြည့်မယ်
git init -q -b main
git config user.name "Thuta Learner"
git config user.email "learner@example.com"
export GIT_AUTHOR_NAME="Thuta Learner"
export GIT_AUTHOR_EMAIL="learner@example.com"
export GIT_COMMITTER_NAME="Thuta Learner"
export GIT_COMMITTER_EMAIL="learner@example.com"
cat > greet.js <<'EOF'
function greet(name) {
console.log("Hello, " + name);
}
greet("world");
EOF
git add greet.js
GIT_AUTHOR_DATE="2026-01-07T09:00:00" GIT_COMMITTER_DATE="2026-01-07T09:00:00" \
git commit -m "Add greet function"
git branch -M main
cat > greet.js <<'EOF'
function greet(name) {
console.log("Hello, " + name + "!");
}
greet("world");
EOF
git diff
git add greet.js
git diff --staged
GIT_AUTHOR_DATE="2026-01-07T10:00:00" GIT_COMMITTER_DATE="2026-01-07T10:00:00" \
git commit -m "Add exclamation to greeting"
git checkout -b feature
cat > greet.js <<'EOF'
function greet(name) {
console.log("Hi there, " + name + "!");
}
greet("world");
EOF
git add greet.js
GIT_AUTHOR_DATE="2026-01-07T11:00:00" GIT_COMMITTER_DATE="2026-01-07T11:00:00" \
git commit -m "Change greeting wording on feature branch"
git diff main...feature$ git diff
diff --git a/greet.js b/greet.js
index c30f984..629b3db 100644
--- a/greet.js
+++ b/greet.js
@@ -1,4 +1,4 @@
function greet(name) {
- console.log("Hello, " + name);
+ console.log("Hello, " + name + "!");
}
greet("world");
$ git add greet.js
$ git diff --staged
diff --git a/greet.js b/greet.js
index c30f984..629b3db 100644
--- a/greet.js
+++ b/greet.js
@@ -1,4 +1,4 @@
function greet(name) {
- console.log("Hello, " + name);
+ console.log("Hello, " + name + "!");
}
greet("world");
$ git diff main...feature
diff --git a/greet.js b/greet.js
index 629b3db..54bea71 100644
--- a/greet.js
+++ b/greet.js
@@ -1,4 +1,4 @@
function greet(name) {
- console.log("Hello, " + name + "!");
+ console.log("Hi there, " + name + "!");
}
greet("world");၅ မိနစ် စမ်းကြည့်
Track လုပ်ထားတဲ့ file တစ်ခု ပြင်ပြီး `git diff` run ပြီး unstaged ပြောင်းလဲမှုကို ကြည့်ပါ။ Stage လုပ်ပြီး `git diff --staged` run ပြီး baseline ကွာတဲ့ ပြောင်းလဲမှုတူညီတာကို ကြည့်ပါ။ ပြီးရင် branch ဒုတိယတစ်ခု ဖန်တီးပြီး ထိုမှာ ပြောင်းလဲမှု တခြားတစ်ခု လုပ်ကြည့်ပါ၊ main ကနေ `git diff main...yourbranch` run ပြီး working directory နဲ့ မသက်ဆိုင်ဘဲ branch က တကယ် ဘာပြောင်းလဲထားလဲ ကြည့်ပါ။
သတိလေးတစ်ချက်
File တစ်ခု stage လုပ်ပြီးနောက် `git diff` run ရင် ဘာမှ မပြပါဘူး၊ ဘာကြောင့်ဆိုတော့ ပြောင်းလဲမှုက staging area ထဲမှာ ရောက်နေပြီဖြစ်လို့ပါ — staged ပြောင်းလဲမှုတွေကို ကြည့်ဖို့ `git diff --staged` လိုအပ်ပါတယ်။
Two-dot (`git diff main..feature`) နဲ့ three-dot (`git diff main...feature`) syntax တွေက မတူညီတဲ့ အရာတွေကို နှိုင်းယှဉ်ပါတယ် — branch ရဲ့ ပြောင်းလဲမှုတွေကို review လုပ်ရင် common ancestor နဲ့ နှိုင်းယှဉ်တဲ့ three-dot ကို သုံးရမှာ ဖြစ်ပါတယ်။
Git Documentation: git-diff — Git & GitHub