Git / Github : Commit got lost
Asked Answered
A

1

6

Here is the scenario that happened (I suppose that's how my problem appeared, but not 100% sure) :

  • Someone sent a PR, I did merge it but then I reverted it, using the Github revert button
  • He did another PR with the same Commits (plus one to correct the error)
  • I merged it (using Github merge button)
  • The commits that has been reverted at the first PR had disappeared from the main repo !

Why did that happened ? How is it possible that now, from the fork that did the PR, it's saying There isn't anything to compare although those commits are not on the branch original of the distant repo..

And finally, how can I restore those commits ?

EDIT : As requested, here is the interesting par of my git log :

* | |   25f28fb Merge branch 'FooUser-develop' into develop
|\ \ \
| * \ \   73768b7 Merge branch 'develop' of https://github.com/FooUser/mainRepo into FooUser-develop
| |\ \ \
| | * | | 2e61235 Invert adresses
* | | | |   d522031 Merge branch 'develop' of https://github.com/mainUser/mainRepo into develop
|\ \ \ \ \
| |/ / / /
|/| | | |
| * | | |   1e6e61b Merge pull request #946 from mainUser/revert-945-develop
| |\ \ \ \
| | * | | | 6767f03 (origin/revert-945-develop) Revert "Corrections"
| |/ / / /
| * | | |   5ccc9cd Merge pull request #945 from FooUser/develop
| |\ \ \ \
| | |/ / /
| | * | | 6e0c08b Corrections structuration
| | * | | f7ade9b Correction
| | * | | 4844437 Nb to Str
| | * | | 1729a83 Fix adress
| | * | | ceab88d Corrections: @ssert
| | * | | a3c8d1a #891 Fix
| |/ / /

I apparently lost most of the first commits (#891 Fix for example).

Searching a bit more, I found for example that some files I added in a3c8d1a (first commit) were correctly merged on 73768b7 (second to last) - they weren't just beore, on d522031, because of the Revert - but then disappeared at 25f28fb (last one).

EDIT 2 : I think the problem was because the fork wasn't sync (he didn't git pull / merge when I accepted his PR and then Reverted it). How could I prevent that ? (by the way to "fix" it I had to Cherry Pick all the commits missing..)

Alienation answered 1/9, 2014 at 13:4 Comment(5)
Can you provide us a git log --graph --oneline --decorate --all from your repository?Zoonosis
There are lots of other commits, I gonna try to clean it a bit !Alienation
Just the last 10 commits should be enough to better understand the situation. Just add -10 to the previous command.Zoonosis
Just updated my post, hope that's clear enough.Alienation
I think the problem was because the fork wasn't sync (he didn't git pull / merge when I accepted his PR and then Reverted it). How could I prevent that ? (by the way to "fix" it I had to Cherry Pick all the commits missing..)Alienation
Y
2

If you revert a merge commit, you need to revert the revert first before you can merge the branch again.

See: https://mcmap.net/q/13430/-re-doing-a-reverted-merge-in-git

Which references http://www.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.txt

Yarak answered 20/9, 2014 at 14:27 Comment(1)
This is what I was afraid of. So when you've got a public repo you really have to be careful about that I guess. Thanks !Alienation

© 2022 - 2024 — McMap. All rights reserved.