Git Product home page Git Product logo

cherry_picking's Introduction

Cherry_Picking ๐Ÿ’๐Ÿ‘ฉโ€๐Ÿ’ป

This repo provide an overall view about ```git cherry-pick``` command. is one of the most useful commands in Git and also it does not change your current Git history rather it adds commits to it. In this tutorial, we will be explaining more about Git Cherry Pick commit and how you can use the Git cherry pick command for including specific changes to your current branch.

We'll get to know the following ๐Ÿ‘‰ :

  • What are the use cases ?
  • How to use it ?

Use Cases of cherry pick :

Although git cherry-pick is useful, it isn't as recommended as traditional merges in many scenarios where cherry-picking would be useful. However, git cherry-pick is comes pretty handy in some scenarios such as :

  • Team collaboration ๐Ÿฆพ.

When a team of developers collaborate in the same codebase it makes it possible for other to review and give feedbasks which help identify and fix bugs also ensure that everyone is on the same page, eventually improve the communication & quality of your code, besides that it increase the productivity and save both time ๐Ÿ•“ and ressources ๐Ÿƒ๏ธ.

In this case git cherry-pick command helps applying individual commits from one branch to another, this can be useful to :

  • Backporting bug fixes: If you have a bug fix that needs to be applied to multiple branches, you can use cherry-pick to apply it to each branch individually.
  • Sharing features: If you are working on a feature that you want to share with other developers, you can cherry-pick the commits for that feature to their branches. For example : A developer is working on a new feature in a development branch. Once the feature is complete and tested, the developer cherry-picks the commits for the feature to the main branch. This allows other developers to start using the new feature immediately.

  • Bug hotfixes ๐Ÿž ๐Ÿ”ง

When a bug is discovered it is important to deliver a fix to end users as quickly as possible. For an example scenario,say a developer has started work on a new feature. During that new feature development they identify a pre-existing bug. The developer creates an explicit commit patching this bug. This new patch commit can be cherry-picked directly to the main branch to fix the bug before it effects more users.

How to use git cherry-pick :

In order to demonstrate how to use git cherry-pick let us assume we have a repository with the following branches:

  • Main
  • Feature

In this example, we are only interested in the seconde commit of the feature branch, applying a traditional merge will bring the whole code from the feature branch and create a new commit in the tip of the main branch. In this case git cherry-pick is very handy.

First of all Identify the commit-hash :

    git log -oneline feature

Change the branch you want to apply the changes to :

    git checkout main

Simply run :

    git cherry-pick "commit-hash-of-seconde commit-in-feature"
Image Alt Text

Now let's check step-by-step a good illustrations of what cherry-pick does โ€” and an animation of these illustrations. src = stack overflow :

Before cherry-picking

So basically we are going to do a cherry-pick of the commit L from the branch feature .

Image Alt Text
Now let's cherry pick the commit L : ```git cherry-pick feature~2```
Image Alt Text

After performing the command our working flow will be as follow :

Image Alt Text

Animated :

Image Alt Text

PS :

The commit L' is from the user's point of view the exact copy of the commit L.
Technically speaking, it's a new, different commit, because L contains a pointer to K as its parent while L' contains a pointer to E .

Execution options of git cherry-pick :

Depends on the situation Useful options could be used with git cherry-pick :

  • git cherry-pick --no-commit

The --no-commit option will execute the cherry pick but instead of making a new commit it will move the contents of the target commit into the working directory of the current branch.

  • -edit

Passing the -edit option will cause git to prompt for a commit message before applying the cherry-pick operation.

cherry_picking's People

Contributors

nadirinab avatar

Stargazers

Youssef Tadlaoui avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.