Reputation: 11
I have two branch lets say one branch is branch_one
and second one is branch_two
.
Now both branches have been used paralleled for different set of developments.
Now, I want to merge some commits from branch_two
to branch_one
, but based on start of time.
I mean branch_two
has around 100 commits we want to merge from 51 commit on-wards on branch_one
.
Upvotes: 0
Views: 717
Reputation: 14449
If you do not want to merge all changes from one branch to another (using git merge
), you can cherry-pick
some of the commits (either single commits or multiple commits at once). See cherry-pick
documentation here or this reply, that elaborates on cherry-picking a range of commits.
As far as I know, there is no direct option to directly merge commits from a certain date, but you can just use the method described here to find the commit created on a certain day and use that commit as the start commit for your cherry pick.
Be aware, however, that cherry-picking does apply the picked commits' changes, but creates new commits. Thus, when you ever merge branch_one
and branch_two
in the future, you will have multiple commits introducing the same changes.
On branch_two:
git log --after="2013-11-12 00:00" --before="2013-11-12 23:59"
Output:
commit 5f3be6775d78k28ee0e4f55c05ec897de3f02360
Author: someone <[email protected]>
Date: Wed Mar 22 17:10:48 2017 +0100
Commit message
On branch_one:
git cherry-pick 5f3be6775d78k28ee0e4f55c05ec897de3f02360~1..<id of the latest commit on branch_two>
Edit: Note the ~1
behind the first commits' id. This is necessary, since cherry picking multiple commits will
[...] not cherry-pick A, but rather everything after A up to and including B. – J. B. Rainsberger
See here.
Upvotes: 1
Reputation: 21
You can use git format-patch command
git format-patch -50 -o <output-directory>
It will generate separate patch file for each commit.
And then apply the patch to branch one
Upvotes: 1