Search code examples
gitgithubgit-mergefast-forward

No-FF for merges from a long time ago


In our Git repository we have a few merges from branches that should have been merged with --no-ff but were not. These merges were made a long time ago.

Is there any way to force/insert a commit as if we were running those old merges with the --no-ff argument?

One of the supers on the project enjoys GitHub's network view and wanted to be able to see the individual branches, which are all merged into one line when a fast-forward occurs.


Solution

  • If you don't mind having a new main/master branch (or overwriting the old one – but remember, rewriting published history is BAD), you could simply re-create the merges, if you still remember, when they were/should have been made:

    1. Checkout the first forgotten/inexistent/missed merge:

      git checkout -b new_master $commit_before_merge
      
    2. Merge the old commits. If you want proper merge messages (including the original branch name), you might want to re-create the old branch temporarily, or edit the message by hand.

      git merge $head_commit_of_old_branch
      
    3. You would then have to use cherry-pick or rebase to copy commits from the original master branch over to the new "mergy" branch. (cherry-pick with commit ranges requires a recent release of Git)

      git cherry-pick $commit_before_merge..$commit_before_next_merge
      
    4. Go back to step 2 and repeat until you are happy with history.

    NB. have backups and test in a local clone first.