Git clean Command
In this page:
git clean -n
git clean -f
git clean -fd
Clean Dry-Run करना
git clean आपकी working directory से untracked files permanently delete करता है -- क्योंकि इसे undo नहीं किया जा सकता, कुछ भी actually हटाने से पहले हमेशा पहले git clean -n (dry run) चलाएँ यह देखने के लिए कि exactly कौन सी files हटेंगी।
उदाहरण: Dry-Running Clean
git clean -n
Untracked Files Delete करना
एक बार dry-run list सही लगे, git clean -f (force) इसने list की हर untracked file का actual deletion perform करता है -- Git को accidental data loss से बचाव के लिए यह explicit force flag चाहिए।
उदाहरण: Deleting Untracked Files
git clean -f
Untracked Directories साफ करना
Default रूप से, git clean सिर्फ loose files हटाता है और अब-खाली folders को छोड़ देता है; -d add करना इसे untracked directories भी हटाने तक extend करता है, आपको genuinely एक clean working tree देते हुए।
उदाहरण: Cleaning Untracked Directories
git clean -fd
Ignored Files साफ करना
आपके .gitignore से match होने वाली files (जैसे build artifacts या dependency caches) एक clean के दौरान भी default रूप से skip हो जाती हैं; -x flag इसे override करता है और ignored files भी delete करता है, एक true from-scratch rebuild के लिए उपयोगी।
उदाहरण: Cleaning Ignored Files
git clean -fx
Interactive Cleaning
git clean -i एक साथ सब कुछ delete करने के बजाय एक interactive menu खोलता है, आपको review, pattern से filter, या individual files select करने देते हुए -- जब आप पूरी तरह sure न हों कि क्या untracked है तब clean करने का सबसे safe तरीका।
उदाहरण: Interactive Cleaning
git clean -i
- बिना dry run के
git clean -fचलाना, ऐसी untracked files delete करते हुए जिन्हें recover नहीं किया जा सकता; पहलेgit clean -nचलाएँ। - यह उम्मीद करना कि
git cleanuntracked folders हटा देगा, जबकि आपको-dचाहिए (git clean -fd)। - यह उम्मीद करना कि यह
.gitignoreमें listed files delete कर देगा, जबकि वे skip होती हैं जब तक आप-xइस्तेमाल न करें।
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)