guy777
guy777

Reputation: 242

Git: remove a duplicate commit

I don't know how but I have the following log :

* 527795c - (HEAD, origin/master, master)
*   b829011 - Merge branch 'master'
|\  
| * 423e3aa - Some files added
| * b4c60f2 - Initial commit
* a838a27 - Initial commit

Commits a838a27 and b4c60f2 are the same (all the modifications are exactly the same).

How I can remove commit a838a27

Thanks

Upvotes: 1

Views: 297

Answers (2)

daft_wader
daft_wader

Reputation: 61

To supplement the answer from VonC (would make a comment, not allowed...) if you have more commits than just 527795c between this merge and HEAD (or if anyone else does) you'll find git rebase saves you cherrypicking every single one.

One way this situation could have arisen is: git checkout --orphan new_branch

Upvotes: 0

VonC
VonC

Reputation: 1324138

If those commits are the same, then b829011 - Merge branch 'master' isn't useful at all.

Your history could be just b4c60f2, 423e3aa and 527795c.

One simple solution would be to:

  • rename the current master branch in master old
  • create a master branch at 423e3aa
  • cherry-pick 527795c
  • delete master-old
  • force push the new master to origin (beware: it will change the history on origin, so make sure to warn any user having cloned that upstream repo bore your changes)

That is:

git branch -m master master_old
git checkout -b master 423e3aa
git cherry-pick 527795c
git branch -d master_old
git push --force -u origin master

Make sure the history is correct before force pushing.

Upvotes: 3

Related Questions