2

In my history, I have 1 commit that seems to be duplicated for some reason (checked the diff and are exactly equal).

$ git log pretty=oneline
...
...
d21971dd55e4b4f62421b6531b3fd1e65102974d Add Source Sans Pro required weights
...
...
8aaba297017086094b60087b5601ccc01d50be54 Add Source Sans Pro required weights
...
...

This changes are in a branch that wasn't pushed yet. How can I get rid of one of those duplicated commits?

EDIT: The dots between the commit logs doesn't means that there are exactly two commits between them. There are more than 10 in some cases.

jviotti
  • 17,881
  • 26
  • 89
  • 148

1 Answers1

5

To get rid of commit d21971 you could do

git rebase -i d21971^

It will open your text editor with the list of commit up to the parent of commit d21971. Just delete the line with commit d21971, save and quit. It will delete it.

To make sure you won't lose any commit even if you make an error, you could tag your current branch first. For example:

git tag safetyTag
git rebase -i d21971^
#Decide that you don't like what you just did
git checkout safetyTag
git branch -f master
gturri
  • 13,807
  • 9
  • 40
  • 57
  • 1
    But note that this is rewriting history, anybody who cloned your repository from before will be left hanging to dry. Also note that the missing commit may mean a cascade of conflicts in the following commits. – vonbrand May 07 '14 at 21:39