1

I wanted to fix the Name and Email on my commits so I ran

git filter-branch --env-filter '
if [ "$GIT_AUTHOR_NAME" = "<OLD NAME>" ];
then
    GIT_AUTHOR_NAME="<NEW NAME>";
    GIT_AUTHOR_EMAIL="<NEW EMAIL>";
fi
if [ "$GIT_COMMITTER_NAME" = "<OLD NAME>" ];
then
    GIT_COMMITTER_NAME="<NEW NAME>";
    GIT_COMMITTER_EMAIL="<NEW EMAIL>";
fi
' -- --all

And

git filter-branch -f --commit-filter 'git commit-tree -S "$@";' -- --all

But this leaves backups and I am having difficulty removing them.

Any idea how I can get rid of them?

POQDavid
  • 195
  • 1
  • 15
  • @TonyArra I actually tested that and it didn't work I could try it few more times but not sure if it would change anything – POQDavid Apr 23 '22 at 19:09
  • If that's the case, please upate your question with debugging details (what did you try; what error messages did you see; etc) – TonyArra Apr 23 '22 at 19:18

1 Answers1

2

A better option, considering git filter-branch or BFG are obsolete after Git 2.22 or more, is to use git filter-repo (python-based, to be installed first):

git filter-repo --path your/big/file --invert-path

Or:

git filter-repo --strip-blobs-bigger-than 10M

Its man page mentions, about git filter-branch:

Despite the use of --all and --tag-name-filter, and filter-branch's manpage claiming that a clone is enough to get rid of old objects, the extra steps to delete the other tags and do another gc are still required to clean out the old objects and avoid mixing new and old history before pushing somewhere.

git filter-repo will force you to make a backup first, then proceed to change the history of the local repository you are filtering.


Note that you still need git filter-repo to sign commit though, as explained in newren/git-filter-repo discussions 209.

See How do I cryptographically sign all commits on a branch?.

Or, as suggested by the OP POQDavid in the comments:

git rebase --exec 'git commit --amend --no-edit -n -S' -i

Or, using the rebase --root option I mentioned here:

git rebase -i --root --exec 'git commit --amend --no-edit -n -S
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Do you happen to know an alternative for `git filter-branch -f --commit-filter 'git commit-tree -S "$@";' -- --all` but with git filter-repo? – POQDavid Apr 23 '22 at 21:20
  • @POQDavid No but you don't need it to fix commit name/email: https://stackoverflow.com/a/58263677/6309 and https://htmlpreview.github.io/?https%3A%2F%2Fgithub.com%2Fnewren%2Fgit-filter-repo%2Fblob%2Fdocs%2Fhtml%2Fgit-filter-repo.html=#_user_and_email_based_filtering= – VonC Apr 23 '22 at 21:27
  • Yes I wanted that to sign all the commits again – POQDavid Apr 23 '22 at 21:41
  • @POQDavid Exactly. One `git filter-repo` command ought to be enough for that, as shown in https://stackoverflow.com/a/58263677/6309. – VonC Apr 23 '22 at 21:58
  • so that would keep the commits signed? – POQDavid Apr 23 '22 at 22:09
  • @POQDavid not with filter-repo indeed (https://github.com/newren/git-filter-repo/discussions/209#discussioncomment-474986). For signing, you [still need `filter-branch`](https://stackoverflow.com/a/71350955/6309). – VonC Apr 23 '22 at 22:25
  • i sort of managed to do it with `git rebase --exec 'git commit --amend --no-edit -n -S' -i` – POQDavid Apr 23 '22 at 22:30
  • @POQDavid That would work too. I have included your comment in the answer for more visibility. – VonC Apr 23 '22 at 22:33
  • I just noticed that leaves the first commit this `git rebase -i --root --exec 'git commit --amend --no-edit -n -S'` just does all the commits – POQDavid Apr 23 '22 at 22:34
  • @POQDavid True. I have edited the answer accordingly, and included the link to the `rebase --root` option. – VonC Apr 23 '22 at 22:40