Home > OS >  Delete all of a user's pushed commits from a repo
Delete all of a user's pushed commits from a repo

Time:01-04

We have a user that we do not want associated with our organization anymore.

Is there a convenient way to remove all of their commits from our repositories while keeping other user's commits?

I have been rebasing, but dealing with the merges is a massive pain.

CodePudding user response:

Generally git filter-branch would be my way to go. It allows you (among other things) to pretend the changes were made by someone else.

But be aware that not only the commits of that specific user will get new IDs but also all commits after the first commit that user ever contributed. This is because of the block-chain nature of git commits. This might disrupt all systems that work with commit IDs like code-review or ticketing systems.

CodePudding user response:

Removing commits seems a bit extreme, since the code associated with that user would also be lost.

I would install newren/git-filter-repo and rewrite the author of those commits, changing its name/email to a dummy one.

See "How to change commit author for multiple commits using filter branch?" and
"git filter-repo / User and email based filtering"

git filter-repo --mailmap my-mailmap

with my-mailmap:

Correct Name <[email protected]> <[email protected]>

That will rewrite your commits with the right author.

You will then need to git push --force (assuming one main branch) in order to override the remote history with your new commits: make sure every collaborator clone the repository again, in order to use the new history.

  •  Tags:  
  • Related