Git ignore (.gitignore)
In this page:
# .gitignore
file_name
*.extension
directory_name/
!exception_file
Specific Files Ignore करना
एक .gitignore file उन patterns list करती है जिन्हें Git को कभी track नहीं करना चाहिए -- एक specific file ignore करने के लिए, बस अपनी line पर इसका exact name लिखें (जैसे secrets.env), और Git इसे git status या git add में offer करना बंद कर देगा।
उदाहरण: Ignoring Specific Files
echo "secrets.env" >> .gitignore
Extension से Files Ignore करना
* wildcard किसी भी characters से match करता है, इसलिए *.log नाम की परवाह किए बिना .log से खत्म होने वाली हर file ignore करता है -- temporary build output या debug logs के लिए एक common pattern जिन्हें आप कभी गलती से commit नहीं करना चाहते।
उदाहरण: Ignoring Files by Extension
echo "*.log" >> .gitignore
Directories Ignore करना
एक pattern को एक trailing slash से खत्म करना, जैसे node_modules/, Git को पूरी directory और इसके अंदर सब कुछ ignore करने को कहता है, जो बड़े dependency folders exclude करने के लिए ज़रूरी है जिन्हें version control में नहीं रहना चाहिए।
उदाहरण: Ignoring Directories
echo "node_modules/" >> .gitignore
Ignore Rules के Exceptions बनाना
कभी-कभी आपको एक specific exception वाला एक broad ignore rule चाहिए होता है -- एक pattern को ! से prefix करना, जैसे !important.log, Git को उस एक file को track करने को कहता है भले ही एक wider rule अन्यथा इसे ignore करती।
उदाहरण: Creating Exceptions to Ignore Rules
echo "*.log" >> .gitignore
echo "!important.log" >> .gitignore
Ignored Status Check करना
अगर कोई file mysteriously track होने से मना कर दे और आपको पता न चले क्यों, git check-ignore -v <file> exactly दिखाता है कि कौन सी line, किस .gitignore file में, इसे exclude करने के लिए जिम्मेदार है -- guess करने से कहीं तेज़।
उदाहरण: Checking Ignored Status
git check-ignore -v debug.log
- किसी file को पहले से commit हो जाने के बाद
.gitignoreमें add करना और इसके गायब होने की उम्मीद करना, जबकि Git इसे तब तक track करता रहता है जब तक आपgit rm --cached fileन चलाएँ। *.logको गलत जगह या*.logsजैसे typo के साथ लिखना, ताकि intended files ignore न हों।- यह उम्मीद करना कि
.gitignoreपहले से pushed secrets protect करेगा, जबकि पहले की commits अभी भी उन्हें contain करती हैं।
git init,git clone,git add, औरgit commitrepositories बनाते हैं और staging environment इस्तेमाल करके changes record करते हैं।git status,git log,git diff, औरgit showयह inspect करते हैं कि क्या बदला है।git rm,git mv,git restore,git clean,git stash, tags, और.gitignorefiles और work in progress manage करते हैं।
Chapter Quiz — Complete all 18 topics to unlock
0/18 topics done
Complete these topics first:
- Git init Command
- Git New Files
- Git Staging Environment
- Git clone Command
- Git status Command
- Git help Command
- Git add Command
- Git commit Command
- Git tags Command
- Git stash Command
- Git log Command
- Git diff Command
- Git show Command
- Git rm Command
- Git mv Command
- Git restore Command
- Git clean Command
- Git ignore (.gitignore)