I don't even know how to summarize this issue, so having a hard time searching for similar questions.
My company has our repos setup so that work for our next release is done by creating a branch from the master branch, making changes, then merging that branch back into master. When we do a release, we create a "release-<#.#>" branch from master. Now if something in that release needs to be modified, we create a branch off of the release-<#.#> branch, make changes, then merge back into the release branch.
I should note that no one is allowed to commit anything directly to master or release branches. The only way to update those branches is by working in another branch, creating a pull request from that branch to either master or a release branch, getting that PR approved, then merging it.
We then have an "auto merge" from the release branch into master, to make sure master always gets those changes as well. I'm not sure if this is a good idea or not (it definitely causes headaches for me often), and not interested in debating that, but I need to figure out how to address the following situation.
I have a file, somecode.java. We branched release-2 from master, did the release. I kept working for the next release, and updated somecode.java in the master branch.
Now we discover that there was a problem with release 2, and I had to make a "fixit" branch from release-2 branch. In the fixit branch, I updated somecode.java, then merged it back into the release-2 branch.
Now the auto merge from release-2 to master fails because the version of somecode.java in release-2 conflicts with the version in master.
Is there some way to tell Git to either
(1) keep the version in master (preferred, since the changes in release 2 have been superseded by the changes made earlier, but after the release-2 branch was created, in master) or
(2) overwrite the version in master with the newer version from release-2 (and then I'll just update the master version later with changes already made to it there)?
I know I could just decline the auto merge pull-request from release-2 to master, but then any time someone else tries to update the release-2 branch, they'll get the same merge conflict when their auto merge is attempted.
I tried doing a
git checkout origin/master -- somecode.java
while working in my "fixit" branch, and then updating the file to be how we need it for the release 2 fix.
I thought that would be the equivalent of telling Git "for this file, we're starting with the master version, so when we update it here, it should clearly overwrite the version in master". Basically option (2) above.
But it didn't make any difference, and still had the same conflict when doing the merge from release-2 to master.
Any suggestions?