Reputation: 113
We're working on a feature branch at work, which will eventually be merged into our main branch. From a workflow point of view, we usually branch off of this feature branch, make changes / add files, then submit a pull request. The problem with this workflow is that we have to merge any changes that other devs have made when we submit the pull request to make sure our branch is up to date. Usually this is as simple as resolving conflicts and moving on, but the issue that we are running into is that when we do a merge from the main feature branch, any changes that have been made get put into my branch which then have to get placed back into the feature branch for the pull request. I was hoping that the answer would be a 'selective merge', where you can tell git to do a merge, but only merge the files I tell it to, not the whole branch.
Example: File A exists in the main feature branch. I create a new branch off this, and make changes to file A. While I was doing that, another dev made changes to file B and got their pull request approved. Now when I merge, I get any updates to file A (what I want, so I can resolve conflicts) and updates to file B (which I don't want, because I would just be putting the same file back into the pull request with no changes). We're using bitbucket, and for some reason it doesn't realize that the files are exactly the same, and they show up in the pull request. QA doesn't like this so I need to find another way.
I have found how to selectively checkout files from another branch into my own, but that will overwrite any changes I have made in my new branch, so this is not really an option.
The TL;DR version is, is there a way to merge only certain files from another branch into my branch?
Upvotes: 2
Views: 334
Reputation: 11571
In Git there is no notion of "selective merge". If you perform a merge and connect two nodes in the commit graph to form a third node,
A
\
-- C
/
B
C is considered the sum of A and B and is assumed to be a straight-up merge of the contents of A and B. Technically you could of course choose to not include all changes introduced in B when you create commit C, but rather than expressing "oh, I just want to ignore those changes right now" (which is what you're looking for) it actually expresses "those changes from B are bad and I'm actively removing them forever".
While the type of selective merge you want is possible with Git, it runs contrary to how things are supposed to work and Git won't supply you with more rope than necessary. This is for a good reason and you shouldn't work around it.
Upvotes: 2