Assume I have a topic branch fix-bug-#25
that has diverged from master
a couple of commits ago:
o--o--o master
\
o--o--o bug-fix-#25
On my third commit in bug-fix-#25
I fixed the bug and want to merge the branch into master
. Should I checkout master first, merge the topic branch into master
git checkout master
git pull
git merge bug-fix-#25
or should I checkout the topic branch and pull from master, before checking out master and merge with the topic branch?
git checkout fix-bug-#25
git pull
git pull origin master
git checkout master
git pull
git merge fix-bug-#25
What's the best way to do this, that minimizes the amount of merge conflicts?
tl;dr: Imho you should merge smaller changes into master
but complete bigger changes on the topic branch.
This is a matter of policy, taste and circumstances.
I don't really like too many merge commits which is why I'd go the first route. (I also git pull --rebase
because of that but that's another story.) It's true that you should test whether master
still works with your fix as ajp15243 mentions (although that is a matter of policy as well) but that can be done on master
as well. If your fix has small problems, you can reset to before the merge, fix the branch and merge again.
However, if the fix has big problems, eg, because master
has had a lot of changes introduced while you were on your topic branch, and requires a lot of work/commits to be fixed, I'd merge master
into the topic branch first. That helps keep master
clean.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.