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

Git mv Command

git mv एक folder label rename करने और teacher को उसी moment नए नाम के बारे में बताने जैसा है, ताकि किसी को न लगे कि पुराना गायब हो गया।
Syntax
bash
git mv old_name new_name
git mv file_name directory/

एक File Rename करना

git mv old-name.txt new-name.txt disk पर एक tracked file rename करता है और automatically उस rename को Git में stage करता है, एक command में वह करते हुए जिसके लिए अन्यथा एक manual mv plus अलग git add और git rm calls चाहिए होतीं।

उदाहरण: Renaming a File

bash
git mv old-name.txt new-name.txt

एक File को Directory में Move करना

वही command files relocate भी करता है -- git mv file.txt src/file.txt एक tracked file को Git की history को इससे connected रखते हुए एक अलग directory में move करता है, इसे delete-and-recreate की तरह treat करने के बजाय।

उदाहरण: Moving a File to a Directory

bash
git mv file.txt src/file.txt

कई Files Move करना

आप target directory से पहले उन सबको list करके एक साथ एक destination folder में कई files move कर सकते हैं, जैसे git mv a.txt b.txt docs/, जो हर move को साथ stage करता है।

उदाहरण: Moving Multiple Files

bash
git mv a.txt b.txt docs/

एक Move या Rename Force करना

अगर destination name वाली एक file पहले से exist करती है, Git इसे चुपचाप overwrite होने से बचाने के लिए move करने से मना कर देता है; -f flag फिर भी move force करता है, वहाँ पहले से जो भी था उसे replace करते हुए।

उदाहरण: Forcing a Move or Rename

bash
git mv -f source.txt existing.txt

एक Move Dry-Run करना

git mv -n old.txt new.txt यह दिखाते हुए एक dry run perform करता है कि rename क्या करेगा, बिना actually किसी file को छुए -- कुछ important rename करने से पहले एक quick safety check।

उदाहरण: Dry-Running a Move

bash
git mv -n old.txt new.txt
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 rename करना और फिर सिर्फ git add चलाना, जबकि git mv old new दोनों steps एक साथ करता है (हालाँकि Git किसी भी तरह rename detect कर सकता है)।
  2. एक untracked file पर git mv चलाना, जो not under version control के साथ fail होता है।
  3. एक file को न मौजूद folder में move करना, जैसे git mv file.txt src/file.txt में, जहाँ src directory पहले बनानी ज़रूरी है।

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.