I'm trying to rewrite git repository history and apply new pre-commit hook:
pre-commit hookThe end state is a new repo with a different commit history.
What I already found:
cherry-pick doesn't run pre-commit hook.git cherry-pick --no-commit
git commit --no-edit
But it doesn't preserve the commit date. Also, not sure how to do that for each commit in history (unless I write a e.g. Python script for that).
Any ideas on how to do that efficiently?
Use the --exec flag to git rebase, possibly with a custom GIT_SEQUENCE_EDITOR to skip the interactive prompt with the pick list. So something like:
GIT_SEQUENCE_EDIT=cat git rebase --root --exec .git/hooks/pre-commit
This will add exec .git/hooks/pre-commit after every pick <commit> in the pick list. If the pre-commit hooks fails, that will interrupt the rebase:
Executing: .git/hooks/pre-commit
warning: execution failed: .git/hooks/pre-commit
You can fix the problem, and then run
git rebase --continue
You can manually resolve the issues, and then git rebase --continue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With