Reputation: 2200
I have a master branch that was branched from by another dev, who then added features. In the meantime, I have made changes to some of the same files. While there is no direct conflict on lines, I am wondering about the different methods to use to merge the other branch back into master, with minimal conflicts.
ASCII art visualisation:
A-B-C-D
\
1-2-3
Am I best off checking out commit A, merging the branch at 3 back in, then reapplying the changes in B through D? Or should I just merge 3 back into D? Or I am sure there's some better way that I am missing.
I am fairly new to git, I think I am getting the hang of it, but I just want to make sure I am using it properly.
Upvotes: 0
Views: 89
Reputation: 15634
What you describe—checking out A
, merging in 1
–3
, then applying B
–D
—is a standard Git technique called rebasing. Assuming there are no conflicts that can't be automatically resolved, you can do it with a single command:
git rebase --onto {commit 3} {commit A} {commit D}
If there are conflicts when doing a rebase, Git will talk you through resolving them.
However, the normal Git workflow is to just merge the branches together. Unless you've some reason not to, I'd advocate just doing the merge.
Merging more accurately reflects the development process; it means you can look at your history and see exactly how a feature was developed then merged into the main code. Rebasing makes your history look artificially clean; sometimes that's useful, but it does hide how things were done.
Upvotes: 1
Reputation: 14621
Say the original branch name of A-B-C-D is "orig". And you are at "3", with branch name "master". Try this:
git rebase orig
Upvotes: 3