This post will elaborate on the method for merging a specific commit of another branch in Git.
How to Merge a Specific Git Commit?
To merge a Git-specific commit, open the Git branch of which you want to merge the commit and note the commit id. Afterward, move to the Git branch in which you are needed to merge the specific Git commit and use the βgit cherry-pick commit-idβ command for merging the commit.
Step 1: Launch the Git Terminal
From the Windows βStartupβ menu, launch the Git terminal:
Step 2: Go to Git Repository
Move to the Git working repository by processing the βcdβ command:
Step 3: View Branches
View all branches of Git through provided command and choose the branch of which you want to merge the commit:
For instance, we will merge the commit of the βdevβ branch:
Step 4: Move to Branch
Use the βgit checkoutβ command to switch to the required branch:
Check the Git log and note the commit id of a specific commit as highlighted below:
Step 5: Switch Branch
Now, move to the branch in which you want to merge the specific commit of another branch through the mentioned command:
Step 6: Merge Specific Commit
Merge the specific commit by utilizing the βgit cherry-pickβ command along with the copied commit id:
Step 7: Verify Commit is Merged
Next, check the logs of the currently opened branch and verify if the specific commit is merged or not:
It can be observed from the output that we have successfully merged the specific commit:
We have demonstrated the procedure to merge a specific commit in Git.
Conclusion
To merge the specific Git commit, first, visit the Git repository. Note the commit id you need to merge. After that, switch to the branch in which you are merging the specific commit of another branch. Next, merge the commit using the β$ git cherry-pick <commit-id>β command. In this blog, we demonstrated the method of merging a specific commit in Git.