Awacate
Awacate

Reputation: 669

Duplicated commits shown in Github but not when doing rebase

Yesterday, I use git filter-branch in order to change some commits who had wrong emails, following this steps. It worked well, but I forgot to tell the rest of contributors to clone again the repository and all the commits have been duplicated. Now, GitHub history looks like this:

GitHub history

I tried to remove the duplicated commits using git rebase -i HEAD~7 as stated here, but when the editor opens, it only shows single commits (ignore the commits related to the merge, just look the ones with the same name as the commits in the previous image):

git rebase

What can I do to fix this mess? Thank you!

Upvotes: 0

Views: 185

Answers (1)

Alan Deep
Alan Deep

Reputation: 2105

Don't worry, your commits are still there, the message might be the same but the commits are not the same. So the commits you're seeing right now are a duplicate (different hash) of the ones hidden.

I suggest using git reflog to go over ur old commits one by one like this:

Step 1:

git reflog

you will have a list of commits like this:

53bc8bb (HEAD -> dev) HEAD@{0}: reset: moving to HEAD
53bc8bb (HEAD -> dev) HEAD@{1}: reset: moving to HEAD
53bc8bb (HEAD -> dev) HEAD@{2}: checkout: moving from using-dagger to dev
32f3ca8 (using-dagger) HEAD@{3}: reset: moving to HEAD
32f3ca8 (using-dagger) HEAD@{4}: checkout: moving from dagger2 to using-dagger
e9058fd (dagger2) HEAD@{5}: reset: moving to HEAD
e9058fd (dagger2) HEAD@{6}: commit: Imported dagger dependencies
b094ab7 (origin/master, master) HEAD@{7}: reset: moving to HEAD
b094ab7 (origin/master, master) HEAD@{8}: checkout: moving from using-dagger to dagger2
32f3ca8 (using-dagger) HEAD@{9}: checkout: moving from dagger2 to using-dagger
b094ab7 (origin/master, master) HEAD@{10}: checkout: moving from master to dagger2

Step 2:

Lookup a commit that you doubt is your checkpoint

Step 3:

you will find your old commits here, if u wanna test them just do this:

If you doubt that b094ab7 is your commit then:

git checkout b094ab7

you will have HEAD detached at b094ab7 but it's ok, just do git log and check your commit history to make sure that your commit is the one you want, if that's it, if this is where you wanna be, then git reset --hard b094ab7 Other wise, repeat Step 1 until you find your checkpoint.

Once you find your checkpoint, you have your commits above (the duplicated ones you showed us), so just cherry-pick each one like:

git cherry-pick <hash>

and you're done

Upvotes: 1

Related Questions