← Back to Git Course | Chapter 2: Basic Commands | Lesson 14 of 18

Git rm Command

git rm अपने folder से एक paper फेंकने और साथ ही librarian को इसे list से cross off करने के लिए बताने जैसा है, सब एक साथ।
Syntax
bash
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

bash
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

bash
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

bash
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

bash
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

bash
git rm -r build/
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. अपने file manager से एक file delete करना और यह सोचना कि यह Git से हट गई, जबकि deletion record करने के लिए आपको अभी भी git rm या git add -A चाहिए।
  2. git rm file चलाना जब आप file रखना चाहते थे, जबकि git rm --cached file इसे untrack करता है और इसे disk पर छोड़ देता है।
  3. uncommitted changes वाली एक file पर git rm इस्तेमाल करना और block हो जाना, फिर -f इस्तेमाल करना और वह काम खो देना।

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.