Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commit changes missing from git merge

I have two branches, A) develop and B) feature

I work on B, and am now ready to merge B into A. A has obviously had a lot of work done, with a lot of other feature branches merging in via pull requests. I pull the latest head of A and for testing purposes, let's say I merge A in to B (Note, I get the same behavior going both directions, but I'm trying to figure out where the problem is).

I merged A in to B, but I have a lot of compiler errors after resolving the merge conflicts. I noticed that there is actually code included in A that is just not making it over to B. This causes the build to fail, and there are many things missing (it's at least one large commit worth of code).

I tracked down the commit that I'm having issues "merging" from A to B. It's not that it's not merging though, I do see it when I type "git log" when B is checked out after the merge. For some reason the actual changes associated with the commit just disappear. There are no merge conflicts regarding the code in question, and I'm certain I never touched that section while working on B so that anything else could happen.

Regarding the "missing" commit (even though I see it in the branches log), what am I supposed to do to recover the actual changes? I would use a diff tool, but I'm worried this is a symptom of a larger problem and that other code that I'm unaware of could also be missing.

I'm fairly new to git, so I'm a little unsure of how to approach this. Please let me know if there's any other information that could be useful.

What I've tried so far:

Merging A in to B, commit is there but code from commit is not Merging B to A, same issue with same code/commit

I've tried rebasing, but the branches are off by many commits with many conflicts. All commits are also on the server so from what I've read this may be a bad idea. Please let me know if I should try rebasing in some direction (A->B or B->A).

like image 676
blurb Avatar asked Sep 11 '17 21:09

blurb


2 Answers

Solution

If it's just one commit that's missing you can easily apply it to the A branch by issuing a cherry-pick command whilst being on the B branch:

git cherry-pick commit_name

This command takes a specific commit (by name) and applies it to the current branch as a new commit. Just check the name of the commit in your log and paste it as an argument.

Here is some more information on the command: https://git-scm.com/docs/git-cherry-pick

More on the probable cause

As to the problem itself. There may be numerous reasons why you are experiencing such a situation, some of which may be trivial, some not. I'd say it's most probable that GIT sees the differences, but for some reason comes to a conclusion that they should not be applied (during the auto-merge process). You would have to check the history of B branch, how and when (with regards to this A commit) was it created and does it have any history with that specific commit.

Anyway, if the changes from that commit are not physically present in the B code, a cherry-pick should help you solve this as it will apply these changes with a NEW commit name thus avoiding any problems.

like image 200
Maciej Jureczko Avatar answered Sep 21 '22 06:09

Maciej Jureczko


One reason can be you merged A to B previously and handled the conflict in a way that your commit missed.

Feature branches which diverged from develop for so long can be hard to merge back to develop (B -> A). To prevent this, one can merge develop to feature (A -> B) after some time to handle conflict between the 2 branches so far. In this case when you merge A and B (in any direction) at a later time git dose not mention the handled conflicts again.

To check this, use "git log" on B before the final merge, if you see the missing commit it means it's already merged to B.

like image 34
Navid Ht Avatar answered Sep 24 '22 06:09

Navid Ht