<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ravi Teja Kolla</title>
    <description>The latest articles on Forem by Ravi Teja Kolla (@ravitejakolla).</description>
    <link>https://forem.com/ravitejakolla</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F243003%2Fa51c07f3-e242-4bd9-b31d-5eb95e30dcdd.jpeg</url>
      <title>Forem: Ravi Teja Kolla</title>
      <link>https://forem.com/ravitejakolla</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ravitejakolla"/>
    <language>en</language>
    <item>
      <title>Git Cherry-pick </title>
      <dc:creator>Ravi Teja Kolla</dc:creator>
      <pubDate>Mon, 20 Jul 2020 20:21:05 +0000</pubDate>
      <link>https://forem.com/ravitejakolla/git-cherry-pick-51k1</link>
      <guid>https://forem.com/ravitejakolla/git-cherry-pick-51k1</guid>
      <description>&lt;p&gt;Cherry picking is the act of picking a commit from a branch and applying it to another.&lt;/p&gt;

&lt;p&gt;Even though git cherry-pick is just a single command, it needs a whole process to get that right. So below are the list of commands need to be executed to have a successful cherry picking 😊&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step:1&lt;/strong&gt;&lt;br&gt;
Clone the remote repository in to local machine and change the root to your repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone remote_repo
cd local_repo

eg: 
$ git clone https://github.com/ravi-kolla/git-cherry-pick.git
$ cd git-cherry-pick
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step: 2&lt;/strong&gt;&lt;br&gt;
Checkout the branch you have changes in and pull all the commits from remote repo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git checkout branch_with_commit
$ git pull //pulls all the commits from from your branch
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step: 3&lt;/strong&gt;&lt;br&gt;
Checkout the branch you want to add the changes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git checkout branch_to_add_changes
$ git pull 
*//pull all the commits to make sure your new branch is up to date before adding new changes*
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step: 4&lt;/strong&gt;&lt;br&gt;
Cherry pick a commit which you want to be added to the new branch by passing commit hash&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git cherry-pick #commit-hash 
$ git cherry-pick 29cebd92
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step: 4.1&lt;/strong&gt; &lt;em&gt;(Incase if you get merge conflicts on executing git cherry-pick)&lt;/em&gt;&lt;br&gt;
Lets say after executing step:4, you came across bellow error 😒&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git cherry-pick 29cebd92
error: could not apply 29cebd92… commit_message
hint: after resolving the conflicts, mark the corrected paths
hint: with ‘git add &amp;lt;paths&amp;gt;’ or ‘git rm &amp;lt;paths&amp;gt;’
hint: and commit the result with ‘git commit’
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;check git status to identify the conflicts and resolve the files mentioned as both modified.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git status

On branch pre-release
Your branch is up to date with ‘origin/pre-release’.
You are currently cherry-picking commit 29cebd92.
(fix conflicts and run “git cherry-pick — continue”)
(use “git cherry-pick — abort” to cancel the cherry-pick operation)

Changes to be committed:

modified: file-path/sample.css
new file: file-path/sample.js
new file: file-path/sample.txt

Unmerged paths:
(use “git add &amp;lt;file&amp;gt;…” to mark resolution)

both modified: file-path/main.js
both modified: file-path/main.css
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once the merge conflicts are resolved add those files to git and then continue with git cherry-pick.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git add file-path/main.js file-path/main.css
$ git cherry-pick --continue
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step: 5&lt;/strong&gt;&lt;br&gt;
You’re all set to push the cherry picked commit(s) to your new branch 😄&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git push //commits you selected will be pushed to the new branch
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Additional info..&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git cherry-pick A^..B
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;where A is the commit hash you want to start from (the ^ will include commit A instead of starting at next commit after A) and B is the commit you want to end after being applied.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git log --oneline
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Gives you list of commits in single line so you can easily select commit hash codes for cherry picking.&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
    </item>
  </channel>
</rss>
