Normalize screwed git history

I was working on a few features and had to do few rebases. Tho something went wrong and now there are lots of duplicate commits with same date and changes but different hashes. How could I restore it?

history

Upvotes: 0

Views: 57

Answers (1)

AElMehdi
AElMehdi

Reputation: 592

You can use Interactive rebasing.

Interactive rebasing gives you the opportunity to alter commits as they are moved to the new branch. This is even more powerful than an automated rebase, since it offers complete control over the branch’s commit history. Typically, this is used to clean up a messy history before merging a feature branch into master

Since I don't know which state you're trying to restore, I will assume that you want just to remove the duplicate commits. The way to go with it will be to rebase in an interactive mode rebase -i base_branch, you will get something like that:

pick d62629a Add custom image
pick 3fe3b9c Add custom image
pick 2e8602b Refactor ...
pick 1b0d561 Add custom image

You'll then just have to change the action pick to drop or simply d for the commits you want to remove like so:

pick d62629a Add custom image
d 3fe3b9c Add custom image
pick 2e8602b Refactor ...
d 1b0d561 Add custom image

That's one way of doing it.

Upvotes: 1

Related Questions