Search code examples
gitmergegitlabgit-merge

Git merge -no-ff transferred commit history, but not content


Faced a bug in GitLab. One of my projects have over 50 modules. So when I merge branches, I use a bash script, instead of using the GitLab merge UI. This has worked fine so far. This time I faced a weird issue. The merge commit transferred the commit history from the source branch to the target branch, but not the content of the source branch. I was trying to merge the branch cr_integrate to the branch cr_release. Locally, I had cr_release checked out.

The script I used for merge is given below:

git pull
git merge --no-ff origin/cr_integrate -s ours
git add *
git commit -m "Integrate merged into Release by script"
git push

The project contains submodules, and the content of the .gitmodules file is different for different branches, hence I used -s ours to avoid conflict. Is there something wrong with the script or is this a bug with GitLab?


Solution

  • hence I used -s ours to avoid conflict

    But -s ours is not a conflict resolution strategy. It is a merge strategy.

    I like reading the docs:

    the ours merge strategy ... does not even look at what the other tree contains at all. It discards everything the other tree did, declaring our history contains all that happened in it.

    [emphasis mine]

    So, now, you say:

    The merge commit transferred the commit history from the source branch to the target branch, but not the content of the source branch.

    Yep. Because that’s what you said to do. Perhaps you meant -s recursive -X ours? That is a conflict resolution strategy.