3

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?

3
  • Have you tried explicitly asking for fast-forward merges with git merge --ff-only master? Commented Feb 26, 2015 at 18:25
  • Instead of using git diff, try git cherry -v master live (and live master). This will tell you what commits are the latter branch that aren't on the former. If you made a commit on live and then later merged it to master, it could have ended up with a different commit hash (even though your file contents are the same)... so maybe things started to skew from there? Commented Feb 26, 2015 at 21:18
  • Thank you for your replies. @dg99: git merge --ff-only master gives fatal: Not possible to fast-forward, aborting.. @hinerm: git cherry -v master live (and live master) both give no result. So strange! Commented Feb 27, 2015 at 16:14

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments