git – Merging a hotfix into dev and master causes divergence

I am following a success Git branching model (aka git-flow).

I did a hotfix following the guidance in the section Finishing a hotfix branch.

  • Can I have different private config files in different git branches?
  • What is the right way to make a branch the new master of a Git repo?
  • Git. How can I track file (folder) only in one branch
  • How can I view original branch of commits (and file changes) using git log?
  • Is master more a release or a development branch?
  • How do I move the past n commits to main, into a separate branch, with git?
  • I created a hotfix branch off master:

    > git checkout -b hotfix upstream/master
    

    Did some work and manually merged it into master:

    > git checkout master 
    > git merge --no-ff hotfix
    

    Then manually merged it back into dev:

    > git checkout dev
    > git merge --no-ff hotfix
    

    I did some more work – made commits against dev. Everything seemed fine. But then when I went to merge dev into master, it could not.

    > git checkout master
    > git merge --ff-only dev
    fatal: Not possible to fast-forward, aborting.
    

    It appears the merge commit from the hotfix is the difference.

    I assumed following this process would keep a common history. What did I do wrong?

  • warning: setlocale: LC_ALL: cannot change locale (C.UTF-8) while using Cloud9 and Openshift
  • What is protected commit?
  • git fsck: how --dangling vs. --unreachable vs. --lost-found differ?
  • Clearcase Vs Git version control
  • Revalidate opcache only after git push
  • How to undo commit operation in SmartGit/Git
  • One Solution collect form web for “git – Merging a hotfix into dev and master causes divergence”

    You didn’t provide specifics about the topology of your history, so beginning with a general case and creating hotfix gives

    $ git checkout -b hotfix upstream/master
    $ git lola
    * 81a514a (dev) Stupendous feature
    * cb4d5e6 Great feature
    * d4a7906 Cool feature
    | * 39e449a (HEAD, upstream/master, hotfix) v0.2
    |/
    * 264ddbc (master) v0.1

    Note: git lola is a nonstandard but highly useful alias.

    Merging hotfix to master gives

    *   567f066 (HEAD, master) Merge branch 'hotfix'
    |\
    | * 1b1b6e3 (hotfix) Fix nasty bug
    | * 39e449a (upstream/master) v0.2
    |/
    | * 81a514a (dev) Stupendous feature
    | * cb4d5e6 Great feature
    | * d4a7906 Cool feature
    |/
    * 264ddbc v0.1

    Merging hotfix separately to dev is where things go off track.

    *   36aa1c8 (HEAD, dev) Merge branch 'hotfix' into dev
    |\
    * | 81a514a Stupendous feature
    * | cb4d5e6 Great feature
    * | d4a7906 Cool feature
    | | *   567f066 (master) Merge branch 'hotfix'
    | | |\
    | |/ /
    |/| /
    | |/
    | * 1b1b6e3 (hotfix) Fix nasty bug
    | * 39e449a (upstream/master) v0.2
    |/
    * 264ddbc v0.1

    At this point, master is not a direct ancestor of dev but its sibling.

    Adding more commits to dev makes master its great uncle.

    * d89aa74 (HEAD, dev) Jason does it again
    * a4dd5bf Jason saves the day
    *   36aa1c8 Merge branch 'hotfix' into dev
    |\
    * | 81a514a Stupendous feature
    * | cb4d5e6 Great feature
    * | d4a7906 Cool feature
    | | *   567f066 (master) Merge branch 'hotfix'
    | | |\
    | |/ /
    |/| /
    | |/
    | * 1b1b6e3 (hotfix) Fix nasty bug
    | * 39e449a (upstream/master) v0.2
    |/
    * 264ddbc v0.1

    Recall that dev gets to master by way of a feature branch, and through --no-ff merges. Perhaps release-1.0 begins with your hotfix and gets another bug fix.

    * f0398ba (HEAD, release-1.0) Bugfix for v1.0
    * d89aa74 (dev) Jason does it again
    * a4dd5bf Jason saves the day
    *   36aa1c8 Merge branch 'hotfix' into dev
    |\
    * | 81a514a Stupendous feature
    * | cb4d5e6 Great feature
    * | d4a7906 Cool feature
    | | *   567f066 (master) Merge branch 'hotfix'
    | | |\
    | |/ /
    |/| /
    | |/
    | * 1b1b6e3 (hotfix) Fix nasty bug
    | * 39e449a (upstream/master) v0.2
    |/
    * 264ddbc v0.1

    Assuming that buttons up the release, this goes back to master with

    $ git merge --no-ff -m "v1.0" release-1.0
    $ git lola
    *   5a384c8 (HEAD, master) v1.0
    |\
    | * f0398ba (release-1.0) Bugfix for v1.0
    | * d89aa74 (dev) Jason does it again
    | * a4dd5bf Jason saves the day
    | *   36aa1c8 Merge branch 'hotfix' into dev
    | |\
    | * | 81a514a Stupendous feature
    | * | cb4d5e6 Great feature
    | * | d4a7906 Cool feature
    * | |   567f066 Merge branch 'hotfix'
    |\ \ \
    | |/ /
    |/| /
    | |/
    | * 1b1b6e3 (hotfix) Fix nasty bug
    | * 39e449a (upstream/master) v0.2
    |/
    * 264ddbc v0.1

    Of course, the exact fix for you depends on the specifics of your history.

    Git Baby is a git and github fan, let's start git clone.