How to Merge a Specific Commit in Git

There are cases when developers need to move a specific commit to another branch of the git repository. In case you also need to solve a problem like this without doing a complete merging, continue reading this tutorial.

In such cases, it is necessary to merge a particular commit.

Find out how to do it in a rather fast and easy way.

Your first step should be checking out the branch you wish to merge a commit in. You can do it by invoking the git checkout command, as follows:

git checkout -b local origin/new

In the above-mentioned command, “local” is the name of the branch . As your second step, us the git merge command, like this:

git merge origin/master --no-ff --stat -v --log=300

In the above-mentioned command, “local” is the name of the branch.

As your second step, us the git merge command, like this:

git merge origin/master --no-ff --stat -v --log=300

For learning about more merging parameters, run:

git merge --help

And, finally, for merging a specific commit, invoke:

git cherry-pick <commit-id>

The Usage of Git Merge

Thegit merge command is targeted at combining two branches. You can also use it for merging several commits into a single history. The merge commits involve two parent commits. Every time a new merge commit is made, git runs an automate merging of different histories. But it will not integrate the data changed in both of the histories. It is known as “version control conflict”.

Merge Conflicts

The merge conflicts happen when different developers edit the same file or when one of them deletes a file on which another developer is making changes. With the purpose of solving such kind of problems, isolated branches are created.

Unlike other version control systems, Git makes it easier to merge. It can also integrate new changes mechanically. But when conflicts occur, Git won’t be able to find out automatically which of the versions is correct. Hence, the process of merging will be stopped by Git, because of the conflict.


Do you find this helpful?

Related articles