git checkout

git

इस्तेमाल

git checkout <branch> | git checkout -b <new> | git checkout -- <file>

branch बदलने और फ़ाइल लौटाने वाला पुराना आदेश, जो git 2.23 में switch और restore में बँट गया; checkout -- <file> बिना commit किए बदलाव हमेशा के लिए मिटा देता है।

आम विकल्प

विकल्पअर्थ
-b <new>create the branch and switch to it
-B <new>create or reset it to the current commit
-- <file>overwrite the file with the staged version, losing your edits
--track <remote>/<branch>start a local branch that follows a remote one
--detachsit on a commit with no branch attached
-fthrow away local changes to switch anyway

उदाहरण

git checkout -b feature/login

branches off the current commit and moves there

git checkout main

switches branch, same as git switch main

git checkout -- src/app.ts

discards uncommitted edits to that file; they are gone

उलझन यह है कि पीछे लौटने के कई रूप हैं — ब्रांच का इशारा हटाना और उलटने वाला कमिट जोड़ना एक बात नहीं।

कैसे पढ़ें

  • बड़े कोष्ठक [ ] उस हिस्से को दिखाते हैं जिसे छोड़ा जा सकता है।
  • तीन बिंदु … का मतलब है एक से ज़्यादा दिए जा सकते हैं।
  • विकल्पों में बड़े-छोटे अक्षर मायने रखते हैं — कुछ कमांड में -r और -R अलग काम करते हैं।

आम सवाल

Q. git checkout क्या करता है?

branch बदलने और फ़ाइल लौटाने वाला पुराना आदेश, जो git 2.23 में switch और restore में बँट गया; checkout -- <file> बिना commit किए बदलाव हमेशा के लिए मिटा देता है।

Q. इसे कैसे लिखें?

git checkout <branch> | git checkout -b <new> | git checkout -- <file> — बड़े कोष्ठक वह हिस्सा दिखाते हैं जो छोड़ा जा सकता है।

Q. कितने विकल्प जानने लायक़ हैं?

यहाँ 6 दिए हैं; पूरी सूची man git में है। यह कमांड git में आती है।

मिलती-जुलती कमांड

man पेज: man git-checkout