git log, show, और diff के साथ Git history देखना


मान लीजिए आप सोमवार की सुबह weather-app खोलते हैं और बिल्कुल याद नहीं है कि आपने शुक्रवार को क्या भेजा था। या कोई सहकर्मी पूछता है कि पिछले हफ्ते temperature conversion क्यों बदला, और आप एक अनुमान की जगह असली जवाब चाहते हैं। The commit loop यह बताता है कि एक commit कैसे save होता है। यह chapter उस history को वापस पढ़ने के बारे में है: क्या हुआ, किसने किया, और कब। उसके लिए command है git log, और यहाँ एक छोटे project के लिए वह सब कुछ है जो यह print करता है:
$ git log
commit 4f2a1c9d8e7b6a5c4d3e2f1a0b9c8d7e6f5a4b3c
Author: Priya Nair <[email protected]m>
Date: Tue Jul 14 09:12:03 2026 +0100
Fix temperature conversion in Celsius-to-Fahrenheit formula
commit 5f3d8b21a90e7c6d5b4a3f2e1d0c9b8a7f6e5d4c
Author: Kwame Boateng <[email protected]m>
Date: Mon Jul 13 16:45:22 2026 +0100
Add five-day forecast to the dashboard
commit 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b
Author: Kwame Boateng <[email protected]m>
Date: Mon Jul 13 11:03:47 2026 +0100
Set up project structureएक command, और project की पूरी कहानी यहीं है: तीन commits, सबसे नए पहले, प्रत्येक के साथ कौन लिखा, कब, और क्यों।
git log के साथ log पढ़ना
git log हर commit को वापस चलता है जो आप जहाँ हैं वहाँ से पहुँचने योग्य है, सबसे हाल का पहले। प्रत्येक entry चार चीजें दिखाता है: एक hash (उस सटीक commit को identify करने वाले letters और numbers की लंबी string), author, date, और message जो इसके author ने लिखा था।
एक commit वह सभी चार चीजें एक साथ bundled हैं: उस समय के हर tracked file का एक snapshot, change को describe करने वाला message, जिसने इसे बनाया, और उस commit का link जो इससे ठीक पहले आया, इसका parent commit। यह parent link ही है जो अलग-अलग snapshots के pile को एक असली timeline में बदल देता है। git log को top से bottom तक पढ़ें और आप उस timeline को backward पढ़ रहे हैं, अब से शुरुआत तक।
Hash पहले में डराने वाला दिखता है, लेकिन आपको पूरी चीज की शायद ही कभी जरूरत होगी। 4f2a1c9d8e7b6a5c4d3e2f1a0b9c8d7e6f5a4b3c और 4f2a1c9 एक ही commit को point करते हैं। Git को यह बताने के लिए कि हर दूसरे commit से अलग है, केवल hash का काफी हिस्सा चाहिए, और पहले सात या इतने ही characters लगभग हमेशा काफी हैं। आप इस chapter के बाकी commands सहित हर जगह short form देखेंगे।
git log हर commit को list करता है, सबसे नया पहले, इसके hash, author, date, और message के साथ। एक commit वह snapshot है plus इसका message plus पहले वाले commit का link। आपको लगभग कभी पूरे hash की जरूरत नहीं है, पहले कई characters Git के लिए काफी हैं कि वह exactly जानें कि आप किस commit का मतलब है। git show के साथ एक commit inspect करना
git log बताता है कि एक commit हुआ। git show <hash> बताता है कि यह exactly क्या किया:
$ git show 4f2a1c9
commit 4f2a1c9d8e7b6a5c4d3e2f1a0b9c8d7e6f5a4b3c
Author: Priya Nair <[email protected]m>
Date: Tue Jul 14 09:12:03 2026 +0100
Fix temperature conversion in Celsius-to-Fahrenheit formula
diff --git a/src/index.js b/src/index.js
index 3f2c1a9..7b8e2d4 100644
--- a/src/index.js
+++ b/src/index.js
@@ -12,7 +12,7 @@ function celsiusToFahrenheit(celsius) {
- return celsius * (9 / 5 + 32)
+ return (celsius * 9) / 5 + 32Top half वही metadata है जो git log दिखाता है। इसके नीचे actual change है: एक line जो - से शुरू होती है वह एक line है जिसे commit ने remove किया, एक line जो + से शुरू होती है वह एक line है जिसे यह add किया, और unmarked lines वह context हैं जो same रहीं। यहाँ यह clearly पढ़ता है: old line ने 32 को parentheses के अंदर group किया, इसलिए यह multiplication के पहले add हुआ। fix parentheses को celsius * 9 के चारों ओर regroup करता है इसलिए 32 आखिर में add होता है, वह operator-precedence bug जिसे Priya का message describe करता है।
git show <hash> एक commit को full में दिखाता है: किसने बनाया, कब, और actual lines जिन्हें यह change किया। Removed lines एक minus sign से शुरू होती हैं, added lines एक plus sign से शुरू होती हैं। यह "यह commit actually क्या किया" का जवाब देने का fastest तरीका है। git diff क्या दिखाता है, और वह trip-up जिसे लगभग सभी hit करते हैं
git log और git show committed history को पढ़ते हैं। git diff उस चीज़ को पढ़ता है जो commit नहीं हुई है: अभी आपकी working directory में बैठे हुए changes, आपके last commit के against compare किए।
$ git diff
diff --git a/README.md b/README.md
index 1c2d3e4..9f8a7b6 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
# weather-app
+A five-day weather dashboard built with vanilla JavaScript.यह वह edit है जिसे आपने README.md में किया, कुछ भी stage या commit करने से पहले दिखाया गया। यह वह part है जो लगभग सभी को उनके first week में catch करता है: git add . run करें उसी change को stage करने के लिए, फिर git diff को फिर से run करें, और यह कुछ नहीं दिखाता।
$ git add .
$ git diffकुछ नहीं printed। edit disappear नहीं हुई, और कुछ गलत नहीं हुआ। Plain git diff आपकी working directory को staging area के against compare करता है, और एक बार जब आपने सब कुछ stage कर दिया, तो वे दोनों अब match करते हैं, इसलिए कोई difference नहीं बचता है दिखाने के लिए। Staging area में waiting changes को देखने के लिए, इसकी जगह git diff --staged use करें।
$ git diff --staged
diff --git a/README.md b/README.md
index 1c2d3e4..9f8a7b6 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
# weather-app
+A five-day weather dashboard built with vanilla JavaScript.Same change, अब visible, क्योंकि --staged staging area को आपके last commit के against compare करता है।
git diff आपकी working directory में edits दिखाता है जो अभी staged नहीं हैं। एक बार जब आप git add से सब कुछ stage कर दें, plain git diff quiet हो जाता है। यह expected है, आपके changes अभी भी वहाँ हैं। git diff --staged use करें commit करने के लिए waiting को देखने के लिए। Git history एक graph क्यों बनाता है
हर commit जिसे आपने अभी तक देखा है exactly एक parent को point करता है, और git log को top से bottom तक पढ़ना एक सीधी line पढ़ने जैसा लगता है। यह एक solo project के लिए hold करता है एक काम की line पर। यह hold करना बंद कर देता है moment branches और merges enter करते हैं, जो अगले Branches में covered है, क्योंकि एक project की real history अलग-अलग lines में split हो सकती है और वापस एक साथ आ सकती है।

