Reputation: 568
I'm involved in a fairly large project which has a lot of developers. For a certain feature development, a new branch was created (let's call this branch feature_a
).
Now while trying to merge the master
into feature_a
, there are multiple conflicts in various "modules", where different developers are responsible for these modules.
How can I independently resolve conflicts in files I'm responsible for and leave the other files unmerged?
Upvotes: 1
Views: 198
Reputation: 51780
You could rewrite the history of feature_a
, to split it in a list of commits where each commit is the responsibility of one single developper, then have each developper merge its "own" code back into master
.
Here is an outline for this idea :
# from branch feature_a :
# create a new branch :
$ git checkout -b merge_feature_a
# find commit where it forked from `master` :
$ git merge-base master feature_1
0125638
# reset current merge_feature_a to this commit :
$ git reset 0125638
# diff feature_a and merge-base to get the full list of modified files :
$ git diff --name-only 0125638 feature_a
# create first commit with files which are Mike's responsibility :
$ git add <files for Mike>
$ git commit -m "feature_a for Mike"
# same for Sally :
$ git add <files for Sally>
$ git commit -m "feature_a for Sally"
# etc ...
# push this new branch :
$ git push origin merge_feature_a
# tell Mike to merge first commit,
# when he's done tell Sally to merge second commit,
# etc ...
What you get this way is a sequence of merge commits, where the end result is (hopefully) the content you wish for.
Bonus points : create a merge commit at the right spot in history
Once the merging process is completed, you can fiddle with the history, so that this content is shown as a commit joining both the orignal master
branch and the original feature_a
branch :
# from master :
# rewind master to its state before any merge :
# use '--soft' to keep every modifications in the index
# (your next commit will have this content)
$ git reset --soft 1e67a9bb # <- insert the hash of the original master
# get the sha1 of the commit for feature_a :
$ git rev-parse feature_a
e9573881e2eff04d219e57dfd4d7739aa5c11693
# write this hash into '.git/MERGE_HEAD' :
$ git rev-parse feature_a > .git/MERGE_HEAD
# commit : the presence of the MERGE_HEAD file indicates a merge commit
$ git commit
Upvotes: 1