nautilus-cyberneering / secure-git-guide

A collections of articles about Git, GitHub and GPG focused on security.
https://secure-git.guide
8 stars 5 forks source link

New article: how to remove commits by their commit message #26

Closed josecelano closed 2 years ago

josecelano commented 2 years ago

Recently I had to remove a lot of commits from a repo having a concrete prefix.

This is the original issue.

The first solution I found was using git filter-branch. It could work but you have to write code to remove the commits in the rebase file.

@da2ce7 proposed to use reposurgeon. And It worked fine.

You have to install the program and it has its own scripting language. I wrote this script:

# Load the project into main memory
# Warning: this command is slow because Subversion is slow.
read ./YOUR-REPO

# Check for and report glitches such as timestamp collisions,
# ill-formed committer/author IDs, multiple roots, etc.
lint

# Commit deletion
/YOUR-COMMIT-PREFIX/c delete

# We want to write a Git repository
prefer git

# Do it
rebuild YOUR-REPO-NEW_FOLDER

And then you can execute it with:

reposurgeon "script remove-commits-with-prefix.rs"

I'm going to add an article explaining the different lines and basic stuff about reposurgeon.