Git .gitattributes
In this page:
# .gitattributes
pattern attribute
* text=auto
*.extension binary
.gitattributes क्या है
एक .gitattributes file आपको यह बताने देती है कि Git specific files या patterns को कैसे treat करे -- line-ending normalization, एक file को binary mark करना, या एक diff/merge strategy चुनना -- ऐसे rules जो repository clone करने वाले हर किसी पर apply होते हैं, personal Git config के उलट।
उदाहरण: What is .gitattributes
echo "*.psd binary" > .gitattributes
Line Endings Normalize करना
Windows और Unix-based systems अलग-अलग line-ending characters इस्तेमाल करते हैं (CRLF बनाम LF); normalization के बिना, दोनों में shared एक repository सिर्फ line-ending differences की वजह से किसी file की हर line को बदली हुई दिखा सकता है, diffs को noise से भर देते हुए।
उदाहरण: Normalizing Line Endings
echo "* text=auto" >> .gitattributes
Files को Binary Mark करना
किसी file type को explicitly binary mark करना Git को इसे text की तरह merge या diff करने की कोशिश से रोकता है, जो images या compiled archives जैसे genuinely binary formats के लिए अन्यथा meaningless या broken output produce करता।
उदाहरण: Marking Files as Binary
echo "*.png binary" >> .gitattributes
Custom Diff और Merge Drivers
उन file types के लिए जिन्हें Git out of the box meaningfully diff नहीं कर सकता -- जैसे Jupyter notebooks या Word documents -- .gitattributes एक custom diff या merge driver script की ओर point कर सकती है जो उस format की structure समझती है।
उदाहरण: Custom Diff and Merge Drivers
echo "*.ipynb diff=jupyternotebook" >> .gitattributes
.gitattributes बनाम .gitignore
दोनों files अलग-अलग problems solve करती हैं: .gitignore Git को बताती है कि किन files को कभी track नहीं करना, जबकि .gitattributes यह बदलती है कि Git जिन files को track कर ही रहा है उन्हें कैसे treat करता है -- line endings, diff behavior, export handling -- वे complementary हैं, alternatives नहीं।
उदाहरण: .gitattributes vs .gitignore
echo "node_modules/" >> .gitignore
echo "*.psd binary" >> .gitattributes
.gitattributesमें* text=autoadd करना औरgit add --renormalize .न चलाना, ताकि files अपने पुराने line endings रखें।- files को
binarymark न करना, ताकि Git उन्हें text की तरह diff या merge करने की कोशिश करे। - file को
.gitattributeयाgitattributesनाम देना, ताकि Git इसे न पढ़े; नाम exactly.gitattributesहोना चाहिए।
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: