开发者

merging some differences but not all

git version 1.7.1

I have create 2 branches i.e. branch1 and branch2.

I have been developing on branch1 and branch2. So both branches are different now.

However, I want to merge branch1 into branch2. But what I am not sure about is that I only want to merge some code changes. I have written some functions in branch1 and I just want to merge th开发者_StackOverflow中文版ose functions and nothing else.

Is that possible using git?


The cherry-pick command to get individual commits from one branch.Then use the method shown here to split the commit into individual commits.

Use the git rebase -i to get the original commit to edit it. Then git reset HEAD^ to selectively revert changes, Then git commit to commit that bit as a new commit in the history.

or

using git add --patch or possibly git add --interactive which allows you to add just parts of a hunk, if you want to split different changes to an individual file

i hope its helps to you


Git reasons in term of snapshot of codes, representing the full content of the all project, commits after commits.

That means you can easily cherry-pick one or several commits from one branch to another (as suggested by KingCrunch in the comments)

But you cannot merge some files (and not others) within one commit.
You can try a rebase --interactive branch1~x in order to edit the last x commits with the relevant changes, splitting those commits into 2:

  • one with common changes,
  • the other with the changes you want to merge.

Then you can reorder those second sets of commits, and rebase them or cheery-pick them on top of branch2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜