← Back to Git Course | Chapter 3: Branching | Lesson 7 of 9

Git cherry-pick Command

cherry-pick किसी दूसरे tree से बस एक pakka हुआ cherry चुनने जैसा है। आप किसी दूसरी branch से एक specific change copy करते हैं बाकी लिए बिना।
Syntax
bash
git cherry-pick commit_hash
git cherry-pick start_hash^..end_hash

Cherry-Pick का Introduction

git cherry-pick <commit> किसी दूसरी branch पर एक specific commit से exact changes copy करता है और उन्हें आपकी current branch पर एक नई commit की तरह apply करता है -- उस branch की दूसरी unrelated commits merge किए बिना एक single bug fix लाने के लिए उपयोगी।

उदाहरण: Introduction to Cherry-Pick

bash
git cherry-pick a1b2c3d

Commits की एक Range Cherry-Pick करना

git cherry-pick <commit1>^..<commit2> एक-एक करके चुनने के बजाय commits की एक पूरी contiguous range को order में apply करता है, जो तब तेज़ है जब आपको किसी दूसरी branch से कई related commits चाहिए।

उदाहरण: Cherry-Picking a Range of Commits

bash
git cherry-pick a1b2c3d^..e4f5g6h

Cherry-Pick Conflicts Handle करना

अगर एक cherry-picked commit आपकी current branch के code से conflict करे, process एक merge conflict की तरह ही pause हो जाती है -- आप conflict resolve करके continue कर सकते हैं, या cancel करके शुरुआत में वापस जाने के लिए git cherry-pick --abort चला सकते हैं।

उदाहरण: Handling Cherry-Pick Conflicts

bash
git cherry-pick a1b2c3d
# fix conflicts, then:
git add file.txt
git cherry-pick --continue
# or: git cherry-pick --abort

Merge Commits Cherry-Pick करना

Merge commits के दो parents होते हैं, इसलिए एक को cherry-pick करना default रूप से ambiguous है -- -m flag Git को बताता है कि apply करने के लिए diff compute करते समय किस parent की line of changes को mainline मानना है।

उदाहरण: Cherry-Picking Merge Commits

bash
git cherry-pick -m 1 a1b2c3d

Conflicts Skip करना

git cherry-pick --skip एक multi-commit pick में सिर्फ current-conflicting commit को abandon कर देता है और अगली पर move करता है, जबकि git cherry-pick --abort सब कुछ वापस cherry-pick शुरू होने से पहले reset कर देता है।

उदाहरण: Skipping Conflicts

bash
git cherry-pick --skip
git cherry-pick --abort
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. एक ऐसी commit cherry-pick करना जो पहले की commits पर depend करती है, conflicts या broken code produce करते हुए।
  2. git cherry-pick a..b इस्तेमाल करना और पहली commit miss करना, जबकि range a exclude करती है और आपको a^..b चाहिए।
  3. एक commit को किसी दूसरी branch पर cherry-pick करना और बाद में merge करना, history में एक duplicate commit बनाते हुए।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.