On Tue, Dec 9, 2025 at 5:11 PM Tim Woodall <[email protected]> wrote:
>
> I want to rewrite git history from the very first commit (which is an
> empty commit) but nothing I can find seems to let me do this other than
> with manual intervention.

Since you want to erase all commits -- including the first -- perhaps
you should take the current set of sources in a state you want them
in.  Recursively delete the .git/ directories.  Then reinitialize the
repo and force push the repo.  That should whack everything in remote
(including history) once the force push is complete.

> This is a one off and doesn't need to be efficient so long as I can
> leave it to get on with it without intervention.
>
> This is what I have: (private-email is a place holder)
>
> ===
> #!/bin/bash
>
> for commit in $( git rev-list --all --reverse master ); do
>    git cherry-pick --strategy-option=theirs $commit
>
>    echo "running sed"
>    sed -i 's/[email protected]/[email protected]/g' $( git grep 
> -l '[email protected]' )
>
>    GIT_AUTHOR_DATE="$(git show -s --format=%ad HEAD)" 
> GIT_COMMITTER_DATE="$(git show -s --format=%ad HEAD)" git commit -a --amend 
> --reset-author --no-edit --allow-empty
> done
> ===
>
> and this runs for a while but then gets stuck due to a merge conflict
> (which I thought --strategy-option=theirs would automatically fix)

Yeah, that often happens to me.  I don't expect git to actually work
in this case.  Eventually, you will have to fix some stuff by hand.

I find it easier to just download the updated files and put them in a
clean checkout.  That is, clone the repo you are fiddling with, and
then manually download the files, and then copy the files into the new
clone.  This way, you don't have to dick around with git. Instead, you
have a clean checkout with the files in the state you want them in.

> ===
> Unmerged paths:
>    (use "git add/rm <file>..." as appropriate to mark resolution)
>          deleted by them: main/b/bootstrap-apt-gawk/package/debian/control
>          deleted by them: 
> main/b/bootstrap-apt-original-awk/package/debian/changelog
>          deleted by them: 
> main/b/bootstrap-apt-original-awk/package/debian/control
>          deleted by them: 
> main/b/bootstrap-apt-original-awk/package/debian/copyright
>          deleted by them: main/d/dpkg-conffile-test/package/debian/changelog
>          deleted by them: main/d/dpkg-conffile-test/package/debian/control
>          deleted by them: main/d/dpkg-conffile-test/package/debian/copyright
>          deleted by them: minimal/buster_dpkg_minimal.sh
>          deleted by them: minimal/buster_minimal.sh
>          deleted by us:   minimal/minimal.sh
>          deleted by them: minimal/sid_minimal.sh
>
> Changes not staged for commit:
>    (use "git add <file>..." to update what will be committed)
>    (use "git restore <file>..." to discard changes in working directory)
>          modified:   main/b/bootstrap-required/Makefile
>          modified:   main/b/bootstrap-required/package/debian/control
> ===
>
> The changes not staged are an artifact of my script not aborting when
> the cherry-pick failed so it still runs the sed command so I get this
> over and over again:
>
> ===
> fatal: You are in the middle of a cherry-pick -- cannot amend.
> error: Cherry-picking is not possible because you have unmerged files.
> hint: Fix them up in the work tree, and then use 'git add/rm <file>'
> hint: as appropriate to mark resolution and make a commit.
> fatal: cherry-pick failed
> running sed
> sed: no input files
> ===
>
> Does anyone know of a way to do this? I'm expecting it to take a long
> time hence why I don't want to have to do manual intervention

Yeah, stop messing with git.  Stop trying to use its endless supply of
options and combinations that make no sense to mortal men and women.

Instead, reinitialize the repo, add the source updated files, and
force push the repo.  The command should end with something like:

    $ git push origin master --force

Jeff

Reply via email to