user4571464
user4571464

Reputation:

Avoid recursive merge in Git

I have a git repository with two branches: master and live. I work on master. Once I deem my changes ready for production, I merge them into live, which is checked out in the production system. I work on the project alone.

With this setup, live always used to simply be a few commits behind master. So when I did a git merge master on live, the merge would be performed via fast-forward.

As of recently, doing git merge master while on live results in a merge performed by the recursive strategy. I don't know if the reason for this is that I once accidentally committed a change first on live, and only afterwards merged it onto master.

git diff master live yields no output, ie. the two branches have the same file contents.

What can I do to get my git repository into a "clean" state so it again uses the fast-forward strategy by default?

Upvotes: 3

Views: 7532

Answers (1)

user4571464
user4571464

Reputation:

I think the problem was caused because:

  1. I accidentally committed something (let's call it A) on live instead of master.
  2. I then committed something else (B say) on master.
  3. I realised I made the mistake 1. and merged live onto master.
  4. I still needed to merge B onto live, so I merged master onto live.

I think this created a "crossing" of commit paths that makes it impossible for git merge to fast-forward.

The solution was to first ensure that the two branches really did have the same contents:

git diff master..live
git cherry -v master live
git cherry -v live master

all yielded no result. Then I changed live to point at exactly the same commit as master:

git branch -f live ae5e70... # Hash of the commit pointed to by master
git push --force origin live:live

Now I can fast-forward again. Note that this can be dangerous and should probably not be done when the repository is shared.

Upvotes: 2

Related Questions