Using git-filter-repo to add file to oldest commit

51 Views Asked by At

The github repo for git-filter-repo has a demo python app that is used to add files to the oldest commit, https://github.com/newren/git-filter-repo/blob/main/contrib/filter-repo-demos/insert-beginning, has a comment saying that it could be done as a one-liner:

git filter-repo --force --commit-callback "if not commit.parents: commit.file_changes.append(FileChange(b'M', $RELATIVE_TO_PROJECT_ROOT_PATHNAME, b'$(git hash-object -w $FILENAME)', b'100644'))"

Given the mix of tools being used here, this isn't making a lot of sense to me. How would the command look running on windows 10, adding a .gitignore file or LICENSE file?

1

There are 1 best solutions below

0
larsks On

I don't think I would use git-filter-repo for this; you can just use git rebase.

  1. Run git rebase -i --root

  2. In the result pick editor, change pick to edit on the first commit.

  3. Back at the shell prompt, git add the file(s) you want to add.

  4. Run git rebase --continue