Every thing you need to know to master git, Part 5, git cherry-pick

To illustrate what is cherry-pick let’s imagine  the following situation: you and another developer start working on project, you will both make some changes, but after a while the other developer find a bug in the code and you are interested in to only apply that hot-fix without taking other changes from another developer, in this situation you should do a cherry pick, so let’s do it:

and you continue with something like:

The other developer checks out the repository and will start working and make the second commit:

and in the third commit, he fixes the problem with A.txt so he would something like this:

And he may continue his work with another commit:

Now you are only interested in the third commit and you don’t want to add other files to your local copy so you have to cherry pick the third commit, so all you have to do is fetch all changes, find the corresponding SHA1 value for the third commit and apply the cherry pick.

And now the file A.txt in repose1 should be same as the file in repose2 while C.txt and D.txt are not added to repose1.

 

 

 

Leave a Reply

avatar
  Subscribe  
Notify of