Git Squash Commits
In this page:
git rebase -i HEAD~number_of_commits
# change "pick" to "squash" on the commits to combine
Squashing का मतलब क्या है?
Squashing कई छोटी, अक्सर messy commits ("wip", "fix typo", "actually fix it") को एक clean commit में merge करता है जो finished change को एक single logical unit की तरह represent करता है — तब उपयोगी जब आपकी in-progress commit history काम करते समय आपके लिए ज़्यादा उपयोगी है बजाय बाद में log पढ़ने वाले किसी के लिए।
उदाहरण: What does Squashing Mean?
git log --oneline
# wip
# fix typo
# actually fix it
Interactive Rebase Instructions इस्तेमाल करना
git rebase -i <base> आपकी commits list करने वाला एक editor खोलता है; पहली को pick छोड़ना और इसके बाद हर commit को squash (या s) में बदलना Git को बताता है कि rebase चलने पर उन हर एक को इसके ऊपर वाली में fold कर दे।
उदाहरण: Using interactive rebase instructions
git rebase -i HEAD~3
# pick a1b2c3d Add login form
# squash e4f5g6h fix typo
# squash h7i8j9k actually fix it
Combined Commit Message लिखना
rebase चलने के बाद, Git सभी squashed commits से messages combine करता है और आपके पूरे change को describe करने वाला एक final message लिखने के लिए एक editor खोलता है, आपकी choice के हिसाब से originals के हिस्से discard या रखते हुए।
उदाहरण: Writing the Combined Commit Message
git rebase -i HEAD~3
# combine messages into one final message describing the change
एक Merge के दौरान Squashing
कई hosting platforms एक pull request पर एक button की तरह squash-merge offer करते हैं, merge time पर branch की हर commit को target branch पर एक commit में collapse करते हुए — यह आपको खुद एक interactive rebase चलाए बिना same clean-history result देता है।
उदाहरण: Squashing during a Merge
git merge --squash feature-x
git commit -m "Add feature x"
Squashed Commits Push करना
पहले से pushed commits को squash करना history rewrite करता है, इसलिए एक plain git push reject हो जाएगा — remote branch update करने के लिए आपको git push --force-with-lease चाहिए, और किसी ऐसी branch पर ऐसा करना जिसे कोई और पहले से pull कर चुका है उनकी local history diverge करवाएगा और उन्हें real pain देगा।
उदाहरण: Pushing Squashed Commits
git push --force-with-lease
- हर commit को
squashmark करना, पहली सहित, जबकि पहली कोpickरहना ज़रूरी है। - पहले से pushed commits squash करना, फिर एक force push चाहिए होना और दूसरों को disrupt करना।
git rebase -i HEAD~3गलत count के साथ इस्तेमाल करना, ताकि इसमें बहुत कम या बहुत ज़्यादा commits शामिल हो जाएँ।
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: