Skip to content

Remove a commit based on its message content or filename with git filter-repo --commit-callback #534

Closed
@tomdev92

Description

@tomdev92

I am attempting to remove a commit from my repository history based on its message or filename by using commit.skip() . However, it seems that once the conditional statement evaluates to true, all subsequent commits in the history are skipped, irrespective of the condition.

The code I have been using to skip a commit based on its filename is the following:

git filter-repo --commit-callback 
 for change in commit.file_changes:
  if b"index" in change.filename:
   commit.skip()

whereas for skip a commit based on its message content is the following:

git filter-repo --commit-callback 
 if b"index" in commit.message:
  commit.skip()

The logic of the conditionals is correct, as when I use

git filter-repo --commit-callback 
 if b"index" in commit.message:
  commit.message = b"new commit message"

it works perfectly fine, affecting only the commits which respect the conditional statement.

I have not found any indication on how the skip() works in the git filter-repo documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions