git rebase

git

इस्तेमाल

git rebase [-i] [--onto <base>] <upstream>

आपके commit को नई नींव पर फिर से रखता है; hash बदल जाते हैं, इसलिए जिस branch को दूसरे पहले ही खींच चुके हैं उसे rebase न करें — वहाँ merge करें।

आम विकल्प

विकल्पअर्थ
-iinteractive: reorder, squash, reword, drop commits
--onto <base>move the range onto a different base
--continuecarry on after fixing a conflict
--abortput the branch back exactly as it was
--skipdrop the commit that will not apply
--autostashstash uncommitted work and put it back afterwards
--autosquashapply fixup!/squash! commits automatically

उदाहरण

git rebase main

replays your commits on top of main, giving them new hashes

git rebase -i HEAD~3

squash or reword the last three commits

git rebase --abort

cancel a rebase and return to the original branch

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

कैसे पढ़ें

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

आम सवाल

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

आपके commit को नई नींव पर फिर से रखता है; hash बदल जाते हैं, इसलिए जिस branch को दूसरे पहले ही खींच चुके हैं उसे rebase न करें — वहाँ merge करें।

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

git rebase [-i] [--onto <base>] <upstream> — बड़े कोष्ठक वह हिस्सा दिखाते हैं जो छोड़ा जा सकता है।

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

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

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

man पेज: man git-rebase