0

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!

Awacate
  • 125
  • 2
  • 10
  • You might have a misconception, because your first words are false: "to change some commits who had wrong emails". No. You _cannot change a commit_. What you did was make a bunch of _new_ commits. The old commits were not destroyed so you still see them as well. In other words, _you_ "duplicated" the commits, but they are not duplicates: the new ones have the corrected email. Also, what you see on github is not a "history"; it's just a list. So this might not be a "mess" at all. – matt May 10 '20 at 20:38
  • As for the rebase pick list, it's correct too. Just to take the first commit, `5fec811`, that is the corrected "nuevo layout" commit. The older `33b987d` still exists on your machine, and you can confirm that by examining the reflog, but it is not the parent of your branch head so it doesn't appear in the pick list. (And by the way, if you proceed to rebase, you will create _another_ set of new commits.) – matt May 10 '20 at 20:43

1 Answers1

1

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

Alan Deep
  • 2,037
  • 1
  • 14
  • 22