Git rm Command
In this page:
git rm file_name
git rm --cached file_name
git rm -f file_name
Directory और Git से Files हटाना
git rm <file> एक step में आपकी working directory और आपकी Git tracking दोनों से एक file delete करता है -- यह disk से file हटाता है और उस deletion को stage करता है, इसलिए आपकी अगली commit file को गया हुआ record करेगी।
उदाहरण: Removing Files from Directory and Git
git rm old-file.txt
सिर्फ Staging Area से हटाना
अगर आप चाहते हैं कि Git एक file track करना बंद कर दे लेकिन actual file आपकी disk पर रहे -- एक config file के लिए common जिसे share नहीं होना चाहिए -- git rm --cached <file> इसे locally delete किए बिना untrack करता है।
उदाहरण: Removing from Staging Area Only
git rm --cached config.local.json
File Removal Force करना
Git एक ऐसी file पर git rm block करता है जिसमें unsaved staged या working changes हों, अभी तक commit न किए काम खोने से बचाव के रूप में; -f (force) flag उस safeguard को override करता है जब आप निश्चित हों कि फिर भी आगे बढ़ना है।
उदाहरण: Forcing File Removal
git rm -f locked-file.txt
File Removal Dry-Run करना
git rm -n <file> एक dry run perform करता है, exactly list करते हुए कि command कौन सी files हटाता बिना actually कुछ भी छुए -- wildcards या पूरे folders involve करने वाले किसी destructive rm command से पहले चलाना उचित है।
उदाहरण: Dry-Running File Removal
git rm -n *.log
Mass File Deletion
git rm को एक wildcard या folder path के साथ combine करना, जैसे git rm -r build/, files के एक पूरे group का deletion एक साथ हटाता और stage करता है, जो उन्हें individually delete करने से कहीं तेज़ है।
उदाहरण: Mass File Deletion
git rm -r build/
- अपने file manager से एक file delete करना और यह सोचना कि यह Git से हट गई, जबकि deletion record करने के लिए आपको अभी भी
git rmयाgit add -Aचाहिए। git rm fileचलाना जब आप file रखना चाहते थे, जबकिgit rm --cached fileइसे untrack करता है और इसे disk पर छोड़ देता है।- uncommitted changes वाली एक file पर
git rmइस्तेमाल करना और block हो जाना, फिर-fइस्तेमाल करना और वह काम खो देना।
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)