1

While working on a feature branch (feature-branch-a) (feature-branch-a branched-off of master), I want to make some fix to master.

Since I have a lots of changes in feature-branch-a, so much that it makes lots of sense to base the fix on feature-branch-a rather than on master branch, I created new branch fixture-B from feature-branch-a (since I will eventually merge feature-branch-a into master). However, I still continue to develop feature-branch-a alongside this new branch fixture-B. Now merging branch fixture-B with feature-branch-a results in Already up to date, so no 'merge commit' was done (as I intended).

Where did I get this wrong/how is this best handled?

Damilola Olowookere
  • 2,253
  • 2
  • 23
  • 33
  • In case you landed on this SO page via chat, note that I accepted @VonC's answer because his contribution provided more context to what happened. You can check the discussion comments on his answer for specific details. – Damilola Olowookere Feb 08 '19 at 08:53

1 Answers1

0

Since feature-b is created from feature-a, a merge of a to b would result in a noop: nothing to merge, since the source branch (feature-a) is already an ancestor of the destination feature-b

 a--a--a  (feature-a)
        \
         b--b--b (feature-b)

A git checkout feature-b ; git merge feature-a won't move feature-b HEAD.

A git checkout feature-a ; git merge feature-b would update feature-a HEAD to feature-b (called "fast-forward merge"):

 a--a--a  
        \
         b--b--b (feature-b, feature-a)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    This doesn't look quite like side by side development: "However, I still continue to develop `feature-branch-a` alongside this new branch `fixture-B`". – Mad Physicist Feb 08 '19 at 06:08
  • @MadPhysicist I know, but that does look like "I created new branch fixture-B from feature-branch-a" and explain what the OP is seeing: "Now merging branch fixture-B with feature-branch-a results in Already up to date" – VonC Feb 08 '19 at 06:10
  • Yeah, one part seems to contradict the other. – Mad Physicist Feb 08 '19 at 06:18
  • So it means it was my mistake to have branched `fixture-B` from `feature-branch-a` and develop both branches simultaneously? (like if I was thinking like git, I should have rather branched `fixture-B` off of `master` and then doing the mergers will make sense since there will now be a divergent point for `fixture-B` and `feature-branch-a`), right? – Damilola Olowookere Feb 08 '19 at 08:10
  • @VonC but your does graph illustration doesn't depict that `feature-branch-a` has moved? (I mean the first graph illustration). The graph looks as though `feature-branch-a` is stagnant and only `fixture-B` moved i.e. 2 commits ahead of `feature-branch-a`! (don't forget I said I was developing both branches side-by-side, meaning while I branched-off and was developing on branch B, branch A was also being developed simultaneously - it never stopped like your graph depicts) – Damilola Olowookere Feb 08 '19 at 08:16
  • @DamilolaOlowookere It was not a mistake, *but*: you did *not* develop both branches simultaneously: only `feature-b`. Which means, merging it to `feature-a` won't do anything, since `feature-a` has not changed. – VonC Feb 08 '19 at 08:16
  • @DamilolaOlowookere You need to edit your question with the exact command you have run to merge (and the `git status` when doing that command), in order for us to judge what was merged to what. And double-check the history of the target branch. – VonC Feb 08 '19 at 08:19
  • @VonC "simultaneous development" in this context means: some days, I work on A, some other days, I work on B. So every now and then I contribute something to both branch and commit same. Now I'm done and merging gives this "Already up to date" message – Damilola Olowookere Feb 08 '19 at 08:20
  • @VonC Unfortunately, I cannot get more details because I had to resolve it manually. I copied branch B's code elsewhere, deleted the branch, recreated branch B off of master, overwrite working tree with the previously backed-up B's code, and then did `git merge feature-branch-a` from B. However, kindly update your answer (especially the graph) to depict/include that the development of `feature-branch-a` and `fixture-B` was going on at same time and remark on what the resulting merge should be so that I be able to mark your contribution as the answer. Thanks :) – Damilola Olowookere Feb 08 '19 at 08:27
  • @VonC for example, to provide more context to your answer, if I had `git merge --no-ff feature-branch-a` from branch B, would I have gotten a merge commit (with those <<<=== conflict markers)? – Damilola Olowookere Feb 08 '19 at 08:30
  • @DamilolaOlowookere Then you must have "worked on A" in another branch than A, or in a detached HEAD. Because "Already up to date" means: all the commits of the destination (A) are *already* ancestors of the source branch (B) – VonC Feb 08 '19 at 08:39
  • @DamilolaOlowookere `git merge --no-ff` would have generated a merge commit, yes, but the conflicts markers are only there if you have edited the same section of the same file concurrently in both branches. – VonC Feb 08 '19 at 08:40
  • @VonC ..now it's beginning to add up. Thanks for the clarifications. However, you brought up something that I don't quite get: how can I possibly work on A "in another branch than A"? (btw, I sure do have other branches in my local repo other than these branches A and B) – Damilola Olowookere Feb 08 '19 at 08:42
  • @DamilolaOlowookere Sometime you think you are in a branch, but you are not: https://www.git-tower.com/learn/git/faq/detached-head-when-checkout-commit, https://stackoverflow.com/q/7124486/6309 – VonC Feb 08 '19 at 08:45
  • @VonC thanks man...I never knew `rebase` can lead to detached head state. I did rebase at a point in time. Now I know better! Thanks again – Damilola Olowookere Feb 08 '19 at 08:51
  • @DamilolaOlowookere did you complete the rebase? I've never been in a detached HEAD state after a rebase. – evolutionxbox Feb 08 '19 at 10:37
  • @evolutionxbox I cannot really tell, but from the contributions on this question so far, that is the only explanation I can give. You have now added another context, i.e. incomplete rebase. I won't want to start digging into git log to confirm that. As I previously mentioned above, I have used a semi-manual-ish way to resolve it :) – Damilola Olowookere Feb 08 '19 at 11:56
  • Take a look into the reflog as well. – evolutionxbox Feb 08 '19 at 12:18