• Skip to main content
  • Skip to primary sidebar

Code Inherit

Simple Programming Code Examples

Merge a specific commit to another branch

15th January 2024 by Site Admin Leave a Comment

To merge a specific commit from one branch to another in Git, you can use the git cherry-pick command. Here are the steps:

1. Identify the Commit Hash:

Use the git log command to find the commit hash of the specific commit you want to merge. For example:

git log

Copy the commit hash that corresponds to the commit you want to merge.

2. Switch to the Target Branch:

Make sure you are on the branch where you want to merge the specific commit. Use the following command to switch to the target branch:

git checkout target-branch

Replace target-branch with the name of the branch where you want to merge the commit.

3. Cherry-pick the Commit:

Use the git cherry-pick command to apply the specific commit to the current branch:

git cherry-pick commit-hash

Replace commit-hash with the actual commit hash you copied.

4. Resolve Conflicts (if any):

If there are conflicts during the cherry-pick process, Git will pause and ask you to resolve them. Open the conflicted files, resolve the conflicts, and then continue the cherry-pick process:

git cherry-pick –continue

5. Complete the Merge:

After resolving conflicts, if any, commit the changes:

git commit

6. Push the Changes:

If you are working in a shared repository and want to push the changes to the remote repository:

git push origin target-branch

Replace target-branch with the name of the branch you are merging into.

Now, the specific commit has been merged into the target branch. Note that cherry-picking creates a new commit in the target branch, and it doesn’t preserve the original commit hash.

Filed Under: Uncategorised

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • Bijoy Converter
  • How to amend previous commit with current changes in git and github?
  • How to install PHP 8.1 alongside PHP 7.4 using HomeBrew in MacOs?
  • Create a shell script to switch 7.4 to 8.1 and vice versa
  • How to reflect PHP8.1 to Apache in MacOS?

Recent Comments

    Archives

    • October 2025
    • September 2024
    • January 2024
    • July 2023
    • October 2021
    • September 2021
    • February 2021
    • January 2021
    • October 2020
    • September 2020
    • August 2020
    • May 2020
    • March 2020
    • February 2020
    • January 2020
    • November 2019
    • May 2019

    Categories

    • Couchbase
    • Cron Job
    • dhis2
    • Linux, MySQL
    • MySQL
    • Oracle
    • Oracle Client
    • PHP
    • SSL
    • Subdomain
    • Uncategorised
    • Wordpress
    • WP
    • Zip

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org

    Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in