3

I have 2 main branches master and development. I recently had to push a hotfix that are commits already merged to development, and to do so I cherry-picked commits from development, created a new hotfix branch, added another commit for the fix, and merged that to master. My question is, how can I now merge the new commit to development without messing up the git commit history?

Roughly, what I did:

git cherry-pick <commit SHA>
git checkout -b hotfix-branch
[make more changes]
git commit -m "Fix issue"
git checkout master
git merge hotfix-branch

Now, if I look at git diff between master and development, the old commits from development is showing up because they're cherrypicked, therefore different commits with the same changes. What is the best way to merge back to development and "fix" these diff?

Edit to add: Alternatively, what should I have done in a situation like this, where a hotfix consists of commits in development branch?

thisisdee
  • 878
  • 3
  • 16
  • 41
  • 1
    What you're talking about it generically how [git flow](http://nvie.com/posts/a-successful-git-branching-model/) works. There's no problem with just merging master back into development now. Git should detect that the same changes exist in both and work it out for you. – scrowler Jan 12 '16 at 01:29
  • @RobbieAverill `git flow` is what we're attempting to do, but in this case, the commits needed for the hotfix were already in development, therefore with cherrypicking, the commits are showing as duplicates (different commits). If I do `git merge master` in development, then the new merge commit shows up in diff on master, even though those changes were already on master. Am I making sense? – thisisdee Jan 12 '16 at 01:33
  • @RobbieAverill Or is it actually okay that these commits are showing up as diff? And that git will take care of it moving forward? What I'm worried about it diverging histories between `development` and `master` branches – thisisdee Jan 12 '16 at 01:35
  • I like this question. I personally don't think there's a problem, but I'm interested to see if someone with more knowledge than me gives you an answer as this is relevant to me too actually. – scrowler Jan 12 '16 at 01:36

1 Answers1

1

You need to cherry pick the fix "downwards" the history tree so that later you can cleanly merge it "upwards" to other branches.

  1. Checkout the merge-base (typically, sometimes further down the tree).
  2. Cherry-pick A resulting in a new commit X.
  3. Merge X back to both of the branches.

After this, both branches will have X in common, which means they both contain the fix.

sevo
  • 4,559
  • 1
  • 15
  • 31