git

Git Cherry-Picking

What is Git Cherry-Picking?

Git is a distributed version control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows.

Cherry picking in git means to choose a commit from one branch and apply it onto another.
This is in contrast with other ways such as merge and rebase which normally apply many commits onto another branch. In other words, cherry-picking is when you want to take the contents of a single commit from another branch and copy-paste them to a destination branch as a brand new commit.

Quick Summary of Git Cherry-picking steps

  • Find the commit hash you want to cherry-pick.
  • Go to your destination branch.
  • git cherry-pick -x commit-hash
  • Resolve conflicts if they occur.
  • If there are notes in the original commit, copy them over.

Detailed Git Cherry-picking process

  1. From the origin branch where you want to cherry pick from, run this command to get the commit has needed:
    <code
    git reflog.

    </code

  2. Make sure you are on the branch you want to apply the commit to.
    git checkout
    Execute the following for the typical cherry-pick command is simply:
    git cherry-pick commit-hash
    As developers, we often perform a series of steps to achieve our objectives. Showing you an isolated cherry-pick command is the same as throwing you the manual and asking you to read it.
  3. If you cherry-pick from a public branch, you should consider using
    git cherry-pick -x commit-hash
    This will generate a standardized commit message. This way, you (and your co-workers) can still keep track of the origin of the commit and may avoid merge conflicts in the future.
  4. If you have notes attached to the commit they do not follow the cherry-pick. To bring them over as well, You have to use:
    git notes copy from_commit_hash to_commit_hash

References:

Etienne Noumen

Sports Lover, Linux guru, Engineer, Entrepreneur & Family Man.

Recent Posts

A Daily Chronicle of AI Innovations in May 2024

AI Innovations in May 2024

2 days ago

Tips for Ensuring Success Throughout Your Career

For most people, a satisfactory career is essential for leading a happy life. However, ensuring…

6 days ago

Different Career Paths in the Pipeline Industry

The pipeline industry is more than pipework and construction, and we explore those details in…

6 days ago

SQL Interview Questions and Answers

SQL Interview Questions and Answers In the world of data-driven decision-making, SQL (Structured Query Language)…

2 weeks ago

Things To Consider When Switching Internet Providers

Before you make the decision to switch your home’s interest service provider, take the time…

4 weeks ago

A Daily Chronicle of AI Innovations in April 2024

AI Innovations in April 2024. Welcome to the April 2024 edition of the Daily Chronicle,…

1 month ago