← Back to Git Course | Chapter 6: Advanced Commands | Lesson 5 of 7

Git blame Command

git blame किसी file की हर line के लिए 'यह किसने लिखी?' पूछने जैसा है। यह person और वह day दिखाता है जब इसे last में बदला गया।
Syntax
bash
git blame file_name
git blame -L start,end file_name

File Line Authorship देखना

git blame <file> किसी file की हर line को उस commit hash, author, और date के साथ annotate करता है जिसने इसे last में बदला, जो पूरे commit log को हाथ से खोजे बिना "किसने यह और क्यों लिखा" जानने का सबसे तेज़ तरीका बनाता है।

उदाहरण: Viewing File Line Authorship

bash
git blame file.txt

Specific Line Ranges Check करना

एक बड़ी file पर blame करना हर single line के लिए annotations dump करता है, जो unhelpful है जब आपको सिर्फ कुछ की परवाह हो। git blame -L 20,40 <file> output को lines 20 से 40 तक restrict करता है, आपको सिर्फ उस function या block पर focus करने देते हुए जिसे आप actually investigate कर रहे हैं।

उदाहरण: Checking Specific Line Ranges

bash
git blame -L 20,40 file.txt

Commit Timestamps दिखाना

Default रूप से date column आपके system locale को follow करता है, जो machines में inconsistent हो सकता है। --date=short एक plain YYYY-MM-DD format देता है और --date=raw raw Unix timestamp देता है, दोनों तब उपयोगी हैं जब आपको consistently parse या compare करने में आसान output चाहिए।

उदाहरण: Showing Commit Timestamps

bash
git blame --date=short file.txt
git blame --date=raw file.txt

White Spaces Ignore करना

एक single reformatting commit (जैसे एक indentation change) real authorship history को एक commit के नीचे दबा सकता है जिसने हर line छुई। git blame -w lines attribute करते समय whitespace-only differences ignore करता है, इसलिए blame reformat को पीछे छोड़कर वह commit ढूँढता है जिसने actually logic बदला।

उदाहरण: Ignoring White Spaces

bash
git blame -w file.txt

Copied Code Track करना

जब code same commit history में कहीं और से move या copy किया गया था, plain blame बस उसे credit देगा जिसने copy-paste किया। git blame -C (या ज़्यादा thorough search के लिए -CCC) उस code के origin को और पीछे follow करता है, इसके बजाय उस commit को credit देते हुए जिसने originally इसे लिखा।

उदाहरण: Tracking Copied Code

bash
git blame -C file.txt
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह मान लेना कि git blame दिखाता है कि किसने पहले एक line लिखी, जबकि यह दिखाता है कि किसने last में इसे बदला।
  2. इसे किसी person को blame करने के लिए इस्तेमाल करना, जबकि इसका मकसद commit और उसका message ढूँढना है जो बताए कि क्यों।
  3. -L के बिना एक विशाल file पर इसे चलाना, सैकड़ों lines print करते हुए जब git blame -L 20,40 file.txt इसे limit कर देता।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.