1

I want to delete many commits from my repo history. By deleting, I mean that I want them to completely disappear from my remote repository on GitLab. Pure and simple. No history, no trace. I know this is not recommended but those are duplicates and they contain sensitive information.

I have a list of SHA-1 like this:

3816b7652c4147216293d1fac3dee2f377417979
0f0a95f4d15a2a8d176f548bde47259956cbb859
90cd0dc615d6928460861da70f024039ce18e06f
f8a371aff5301c69825dbd6aec7898fb2c122a79
619dd79966ef4636134bc55f1ef3f03f94cb9dd4
a556b303021c2da0094d42605ce426ef9e74a765  
.  
.
.

They are the commits I want gone. They can be on the master branch or other branches. git rebase -i <SHA>^ could be a great tool and I don't really mind finding the lines matching my list by hand. But when I save the git-rebase-todo file I have merging errors. I don't want to be disturbed by those, I just want to delete the commits as if they never existed. That's all.

ggrelet
  • 1,071
  • 7
  • 22

1 Answers1

2

You would need a combination of:

  • git replace to replace a commit by its parent (if the parent is not part of your list), as seen here;
  • git filter branch to make that replacement permanent (changing all the sha1 of your remaining commits in the process, by the way)

That need to be scripted as this is not a native feature in Git.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250