Depending on the work carried out in your branch and the branch you are trying to merge in, there may be times when Git is unable to automatically merge the other branch into yours. This isn't a bad thing, it's actually Gits way of saying "I don't know how to resolve this, I need a human". If you're using MDOQ Manage Magento Hosting this can be resolved through VSCode.
This guide will walk through the process of how we resolve the merge conflicts, your code will be different and may require you to discuss with the developer(s) responsible for the conflicting commits before you can correct.
Identifying the issue
If you see a message like this when trying to merge a branch into your instance then you will need to manually merge the remote branch in.
Resolving the issue
- Open VSCode for your instance. (Helpers > VSCode)
- Click the source control icon on the left
- Select the "Extra Options" (three dots) then click pull
- Select the "Extra Options" (three dots), hover over "Pull, Push", then select "Fetch"
- At this point all our local copies of the remotes are up to date, we can now proceed to merge the branch we want in.
Select the "Extra Options" (three dots), hover over "Branch", then select "Merge Branch..."
- You will then get a dialog where you can select the branch you want to merge in. Type in the text box to filter the list, and then select the branch you want to merge in.
- Once you select the branch a few things will happen.
Firstly you will see the message that Git failed to auto merge the branch in
Secondly the source control changes list will populate with all the changes that were attempted to be pulled in. (You can use the arrows to the left to expand the list)
(N.B if you see a message about there being an error with "unrelated historys" from the VSCode terminal run `git fetch --unshallow` and repeat this step)
- The "Staged Changes" are ones Git automatically pulled in, so we don't need to worry about them.
The "Merge Changes" are the ones we need to resolve.
Expand the list to see the files we have conflicts for.
Here we can see we only have one file "_colors.scss" with conflicts, though there may be multiple.
The process for resolving the conflict just needs to be repeated for each file until "Merge Changes" is empty.
- Select a file
This will open the file and show the conflict.
In green - the changes in your branch to this file
In blue - the changes from the external branch to this file
There are a couple of options:
- "Accept Current Change" - this will reject the changes from the external branch and only include the change from your branch
- "Accept Incoming Change" - this will reject your changes and only include the changes from the external branch
- "Accept Both Changes" - this will include changes from your branch and the external branch
- Alternatively you can choose to manually edit the file. (This is useful if you need to include bits from each branch)
Work though all conflicts in this file.
- Once happy add the file to the staged changes. (click the plus button on the file)
- Repeat steps 9 & 10 until there are no files left.
- You should now have no "Merge Changes" showing.
click the commit message, you can leave as is, or change to something more specific.
With your cursor still in the commit message press "Ctrl" + "Enter" (This will commit the merge)
- You will now have one staged change ready to push.
- Select "Extra Options" (three dots) then click "Push"
- If you check Github (or whatever source control flavour you use) you will see your new merge commit.
- You should be good to crack on with whatever you were doing before.