user658587
user658587

Reputation:

How can I completely remove/destroy commits from a git repository?

On the surface, this may seem the same as a million similar questions about altering history in git repos, but I believe my case is a bit different and I haven't found a solution that works for me.

I have a git repository, and at one point, one of the programmers accidentally, somehow, brought in code from a different repository, and the whole history of that (previously unrelated) repository is now part of my repositories commit log.

Looking at the commits, it is very clear the exact commit that "brought in" this history from the previously unrelated repo.

After the said commit, we did not touch any of those files.

I want to completely destroy all of these unrelated commits from my repository. I don't mind if I have to do it commit by commit, but I want my repo to truly reflect our own code only.

If it helps, the structure is something like this:

Upvotes: 15

Views: 3465

Answers (1)

Sergey K.
Sergey K.

Reputation: 25386

You need to do an interactive rebase:

git rebase -i <hash-of-the-commit-1034>~

Remove the commit 1034 from the list. Run git garbage collector:

git gc

Push into the upstream:

git push -f

This will wipe clean the commit 1034 from your repo.

Upvotes: 5

Related Questions