gitversion-controlgitlabgit-mergemerge-conflict-resolution

Why is my merge request showing "additions" that are already in my destination branch in GitLab?


I have a staging and main branch in Git that seem to have gotten a bit out of sync. I'm using GitLab, and opened a merge request from stage to main just to see what the difference between the branches is. The difference seems to include "changes" that are already in the main branch, which I'm a little confused on. For example, one of the changes that shows up in the "changes" tab is the addition of a file that is already in the main branch and the two files are identical.

There are, however, a couple of commits that I see on the staging branch that have not made their way into the main branch yet. Which is fine and I'd like to keep them out of the main branch for now.

I'd like to know how I can get the branches in sync so that when I open a merge request from stage to main, the only changes are the ones that are actually not in main. Why are files that are already in main showing up as being "additions" when I open my merge request?

I'd ideally like to not touch the main branch, and instead rebuild the staging branch with what is in main, and keep the commits on stage that are not in main.


Solution

  • This happens because there are commits in your staging branch that have already been merged into your main branch.

    It is a visual inaccuracy at Gitlab level, but it is not a problem git wise. Gitlab shows all commits as changes in its web interface. Git is smart enough to pick the new commits in staging and add them on main after the last commit that was merged, so you could be merging safely.

    You can fix the visual inaccuracy by merging the main branch on the staging branch:

    git fetch origin main:main
    git checkout staging
    git merge main
    # fix conflicts, if any
    git push