-1

I use to work with a partner and each of us works in a parallel branch.

Sometimes, I want to merge some change that he have commited but I do not want to merge all the commits that are in his branch.

If I merge his branch, I will merge the commit that is pointed out by his branch and all this ancestors. It is not I want.

If I merge a specific commit, I will merge that commit and all this ancestors. It is not I want.

How can I merge the changes included by only one commit in my branch without merging his ancestors?

Explanation: My partner works in their files and I work in mine. But sometimes, one of us changes a file that is common for both, so we need to merge only the change that was made in the commom file.

Bruno Carneiro
  • 401
  • 3
  • 14

2 Answers2

1

cherry-pick is indeed what you want in this case. It allows you to specify a commit hash to apply on to your current branch:

git cherry-pick <commit>

When merging branches in with cherry-picked commits, git should be able to fast-forward over these commits, ensuring you don't end up with duplicated commits.

One problem with this flow is if a problem is discovered in a commit that has been cherry-picked. The change would need to be applied to both your branches.

A recommendation from me would be rather than cherry-picking commits, merge those commits in to your main branch. This makes it much easier for you both to keep up to date.

Matthew Hallatt
  • 1,310
  • 12
  • 24
0

I think cherry pick is what you are looking for:

git cherry-pick <commit>

Check this: https://stackoverflow.com/a/9339460/3790546

Pablo
  • 307
  • 3
  • 8