Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
882 views
in Technique[技术] by (71.8m points)

github - Git: Merge a Commit into a different Branch

So I have 3 branches;

  • develop - my continued development branch
  • version_1 - a release branch
  • version_2 - a release branch

I had to do a hotfix on version_2 to reship that version, it was a 2 line change in 2 files, very small.

I wanted to apply that fix to version_1 and develop.

So I;

git checkout version_1
git merge <commit checksum>

I thought a commit only contains the changes, so would only apply those. But the merge conflicts because it tries to update all the changes between the two branches.

Is there a way to merge/move/apply ONLY the changes in a small commit to other branches?

I could just manually re-implement the hotfix on those branches, but this seems a lot of hard work, especially as more hotfixes may need to re applied and rolled out to all other branches.

Cheers, Will
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Merging only one or a few commits mean using git cherry-pick

First cancel the merge you just did: see "Undo a Git merge?".
Then:

git checkout version_1
git cherry-pick <commit checksum>

That can apply to multiple commits or a range of commits: see "How to cherry pick a range of commits and merge into another branch".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...