Reputation: 5473
I tried using a git filter-branch
command I've seen in a related post to rename a batch of old commits. The result is that now my repo has a number of identical commits with different authors. It left me with the following scenario:
A' -> B' -> C'
\
A -> B -> C -> D -> E -> F
A'
is identical to A
except for the commit author, and the same for B'
and C'
. I'd like to remove all references and history of A'
, B'
, and C'
. Note: none of these commits are on a branch or have a tag.
How do I remove the duplicate commit history? This is the result I'm after:
A -> B -> C -> D -> E -> F
My reason for this is to simply clean up the history. I am the only one who touches this code, and I know this wouldn't be a good thing to attempt on any kind of non-trivial repo. Also, it seems as though there are many similar questions, but I can't seem to piece together a working solution.
Thanks!
Upvotes: 2
Views: 382
Reputation: 5473
EDIT: Well, this almost worked. The only problem I see from this is that it overwrote the submission times for the most recent commits (D+).
It seems I've found a solution. I was dancing around it all day, but finally figured out the correct commits to reference. Going by my example above, I cloned a new repo with the latest master branch. From there I found the C
commits' hash, which represents the last know good state. Then I run rebase in interactive mode:
git rebase -i <the C commits' hash>
In the editor that appears, only the duplicate commits that I wanted to delete appeared (up until current history). So I removed all the old duplicate entries up to the D
commit. After saving the rebase command completed without error.
At this point my local repository seemed to have everything in order, so I forced it onto the server:
git push --force origin master
The end result seems to be exactly what I was looking for:
A -> B -> C -> D -> E -> F
Not sure if it is the best way, but then again this isn't really something you want to be doing.
Upvotes: 1