-1

Here is the situation :

I have a develop branche and a feature branche, when finishing the feature I want to merge it into develop. Conflicts arise so, I first pull develop into feature to resolve it then commit the modifications BUT :

I commit only the file with the conflict resolved and forget the rest. So when I merge feature into develop it rollback lots of commits...

origin develop>  ----o-c-c-c-o-------m------
                      \       \     /
 local feature>        f-------m-r-o

The commits 'c' are merge with feature but when merging again with develop I forgot them.

How can I solve this ?

EDIT :

I'm not very experimented with git so i'm asking to have an answer more specific to my problem than the everage git reset response

An-droid
  • 6,433
  • 9
  • 48
  • 93
  • 1
    Possible duplicate of [How do you undo the last commit?](http://stackoverflow.com/questions/927358/how-do-you-undo-the-last-commit) – Ferrybig Feb 08 '16 at 11:00
  • if it's a merge and not a rebase, you can still commit and push local changes to develop... – n00dl3 Feb 08 '16 at 11:03
  • The problem is that the merge undone a massive amount of modifications (file modified, files added, files deleted .. etc) the solutions i've found like the one you provide @Ferrybig are just too simplistic :/ – An-droid Feb 08 '16 at 11:05
  • @An-droid Merges aren't undoing things by their own, are you sure the merges when correct, and you didn't had someone who thought "I don't want to commit all those project files" when phased with the merge conflict. Can you inspect all the commits with `git checkout` and see what commits contain the correct state, and what commits are broken. If you have that list you can use `git cherry-pick` to pick the commits to a new feature branch containing the correct things. – Ferrybig Feb 08 '16 at 11:11
  • @Ferrybig as i said during the merge I commited only the file concerned by the conflict and omitted the rest (I cleaned the index by habit, when I should have commit everything with the conflict resolution) the commit that contain the correct state is the one before the merge – An-droid Feb 08 '16 at 11:18

2 Answers2

1

You have made a bad merge.

origin develop>  ----o1-c1-c2-c3-o2---------m2------
                      \           \        /
 local feature>        f1----------m1-r1-o3

You mistake is in commit m1 and the changes propagated further down the chain.

Rewriting history

The cleanest solution to this problem would be rewriting history so everything is is still flowing correctly. However, this breaks history for every, so they need to reset their branch to the new head, only recommended if you seen your mistake before you pushed.

The fix is redoing the merge, then redoing the final merge with the master.

  1. on branch: feature: git reset --hard f1

    We are going back to the state of the branch at commit f1

  2. on branch: feature: git merge o2

    Redo our merge, making sure we aren't discarding our index this time

  3. on branch: feature: git cherry-pick r1

    Include the changes introduced in commit r1

  4. on branch: feature: git cherry-pick o3

    Include the changes introduced in commit o3

  5. on branch: feature: git push -f

    Force push our fixed feature branch

  6. on branch: feature: git checkout develop

    Switch to develop, so we can fix it

  7. on branch: develop: git reset --hard o2

    We are going back to the state of the branch at commit o2

  8. on branch: develop: git merge feature

    Redo the feature to master branch merge, this fixes the whole chain.

  9. on branch: develop: git push -f

    Force push our fixed develop branch.

Ferrybig
  • 18,194
  • 6
  • 57
  • 79
1

Since you have already pushed, the safest thing to do (while on develop) is to cherry pick the lost commits. For each commit C, run git cherry-pick C.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54