Git rebase Command
In this page:
git checkout feature_branch
git rebase base_branch
git rebase -i base_branch
git rebase --continue
Basic Rebase
Rebasing commits की एक sequence लेता है और उन्हें एक-एक करके एक अलग base commit के ऊपर replay करता है, एक merge द्वारा छोड़ी जाने वाली branching structure की तुलना में एक cleaner, linear-दिखने वाली history produce करते हुए।
उदाहरण: Basic Rebase
git checkout feature-x
git rebase main
Rebase Continue करना
अगर rebase के दौरान किसी commit को replay करना एक conflict पैदा करे, Git operation के बीच में pause हो जाता है -- आप affected files में conflict resolve करते हैं, उन्हें stage करते हैं, फिर बाकी commits replay करना resume करने के लिए git rebase --continue चलाते हैं।
उदाहरण: Continuing Rebase
git add file.txt
git rebase --continue
Interactive Rebase
git rebase -i <commit> आपकी हाल की commits list करने वाला एक interactive editor खोलता है, आपको messages reword करने, कई commits को एक में squash करने, उन्हें reorder करने, या जिन्हें अब नहीं चाहिए उन्हें drop करने देते हुए -- history share करने से पहले इसे साफ करने के लिए powerful।
उदाहरण: Interactive Rebase
git rebase -i HEAD~3
किसी दूसरी Branch पर Rebase करना
git rebase --onto <newbase> <oldbase> <branch> सिर्फ आपकी branch की unique commits को एक अलग target पर replay करता है, एक intermediate branch को पूरी तरह skip करते हुए -- तब उपयोगी जब आपकी branch का actual parent बदल गया हो।
उदाहरण: Rebasing Onto Another Branch
git rebase --onto main old-feature new-feature
Safe Rebase Practices
कभी उन commits को rebase न करें जो पहले से pushed हैं और जिन पर दूसरों ने build किया हो -- ऐसा करना उस history को rewrite करता है जिसे दूसरे लोगों के clones अभी भी reference करते हैं। अगर आपको बिल्कुल एक rebased branch push करनी है, plain force push के बजाय --force-with-lease इस्तेमाल करें, जो कम से कम किसी और के नए commits को चुपचाप overwrite होने से बचाता है।
उदाहरण: Safe Rebase Practices
git push --force-with-lease
- एक ऐसी branch rebase करना जिसे दूसरे पहले से pull कर चुके हैं, जो shared history rewrite करता है और teammates के लिए problems का कारण बनता है।
- एक conflict के दौरान
git addऔरgit rebase --continueके बजायgit commitचलाना। - गलत branch पर rebase करना, जैसे
featureपरgit rebase featureचलानाmainके बजायfeatureपरgit rebase mainके बजाय।
Chapter Quiz — Complete all 9 topics to unlock
0/9 topics done
Complete these topics first: