Git restore Command
In this page:
git restore file_name
git restore --staged file_name
git restore --source=commit_hash file_name
Working Directory Changes Discard करना
git restore <file> एक unwanted edit को file के last committed state पर वापस revert कर देता है, आपके local, unstaged changes discard करते हुए -- यह edits फेंकने के लिए git checkout इस्तेमाल करने का modern, ज़्यादा explicit replacement है।
उदाहरण: Discarding Working Directory Changes
git restore file.txt
एक File Unstage करना
अगर एक file पहले से git add से staged है लेकिन आपने अगली commit में इसे शामिल करने का mind बदल लिया है, git restore --staged <file> आपके actual edits working directory में untouched छोड़ते हुए इसे unstage करता है।
उदाहरण: Unstaging a File
git restore --staged file.txt
एक Specific Commit से Restore करना
git restore --source=<commit> <file> history के किसी भी specific point से एक file के contents खींचता है, सिर्फ last commit से नहीं, आपको उस पूरी commit checkout किए बिना एक पुराना version recover करने देते हुए।
उदाहरण: Restoring from a Specific Commit
git restore --source=a1b2c3d file.txt
साथ Unstaging और Restoring
एक command में --staged और --source combine करना एक file को unstage करता है और उसकी working copy को एक single step में एक past commit के version में reset भी करता है, इसे दो अलग commands की तरह करने के बजाय।
उदाहरण: Unstaging and Restoring Together
git restore --staged --source=a1b2c3d file.txt
Patch Mode Restoration
git restore -p <file> एक interactive, hunk-by-hunk prompt खोलता है ताकि आप किसी file के changes में से सिर्फ कुछ discard कर सकें और बाकी रख सकें -- तब उपयोगी जब एक file एक unwanted experiment को उस fix के साथ mix करे जिसे आप actually रखना चाहते हैं।
उदाहरण: Patch Mode Restoration
git restore -p file.txt
git restore file.txtचलाना और changes वापस पाने की उम्मीद करना, जबकि यह uncommitted edits permanently discard करता है।- एक file unstage करने के लिए
git restore file.txtइस्तेमाल करना, जबकि unstaging के लिएgit restore --staged file.txtचाहिए। - एक commit के साथ
--sourceइस्तेमाल करना और यह भूल जाना कि यह working file overwrite कर देता है, इसमें uncommitted changes खोते हुए।
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)