Reputation: 3360
In our git workflow (using GitHub Enterprise) we have feature branches that have to be merged into two different and independent branches (dev and master). That works well as long as there is no merge conflict.
For example, two feature branches merged into dev have conflicting changes for file F. Both changes should end up in dev, but I don't want dozens of unrelated changes from dev getting merged into my feature branch because they would end up later in master and that's not okay.
What we tried:
git merge
on a single file.git checkout dev --patch -- F
gives you a horrible interface based on vim which I don't dare to propose to my team.--merge
option in git checkout
which simply seems to overwrite changes.git checkout --conflict=diff3
had exactly the same result.The best we came up with so far was to do the changes in GitHub and to revert the merge in the feature branch afterwards but that doesn't look like a clean and solid solution to me.
Upvotes: 2
Views: 6275
Reputation: 3396
The problem is, you do not merge files in git. You merge commits. Therefore, whatever the commit contains, it is supposed to be included in the merge except you can hand pick and edit final contents of the merge. But that is supposed to be used for resolving conflicts and that kind of staff.
Maybe you can split your commit in the feature branch into two commits, so that the first commit will only contain the changes to the file in question, and the second commit will add the rest. And you can only merge up to that commit.
Upvotes: 4
Reputation: 489918
Merging a file requires three versions, not two:
--ours
or LOCAL version, whatever you'd like to call it. That's the one with your changes.--theirs
or REMOTE or other version: again, whatever you'd like to call it is not that important; it's the version of the file with their changes, whoever "they" are.You get these files from anywhere you'd like. When you run git merge
, Git gets all three of these for you:
git checkout
or git switch
.git merge theirbranch
, for instance, uses the name theirbranch
to look up the commit hash ID of the commit that contains their version of this file.git merge-base
program, provided you know the right two commit hash IDs, or have names for them: Git itself runs git merge-base --all HEAD theirbranch
, for instance.If you'd like to merge just one file, you will have to locate all three copies of the file in some manner. Exactly how you do that is up to you. Then you simply use the git merge-file
command, as described in its documentation.
Upvotes: 1