Home > database >  Why is my merge request showing "additions" that are already in my destination branch in G
Why is my merge request showing "additions" that are already in my destination branch in G

Time:10-29

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.

CodePudding user response:

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

CodePudding user response:

Based on what you've said so far, it sounds like your Git workflow is a bit odd. Get back to basics with Git and get a basic Gitflow workflow setup, or a simpler version depending on your needs.

Ultimately it's extremely simple...

  1. Create Feature Branch from Dev branch
  2. Do work in Dev branch
  3. Pull Request to merge changes from Feature Branch --> Dev Branch

Job done. And move up the stack accordingly.

Whenever you see changes in a Pull Request that shouldn't be there, generally it's because you are merging Dev --> Feature Branch before doing Step #3 above which causes more problems and weird behaviour like you are experiencing.

Hopefully the above is a few hints to get you going in the right direction. But without knowing the specific details step by step of your existing Git workflow, it's an impossible question to answer.

  • Related