Skip to content

Instantly share code, notes, and snippets.

@BenSYZ
Last active February 4, 2024 05:35
Show Gist options
  • Save BenSYZ/fedd78772ce7a3ab3bb5213fa8866321 to your computer and use it in GitHub Desktop.
Save BenSYZ/fedd78772ce7a3ab3bb5213fa8866321 to your computer and use it in GitHub Desktop.
#!/bin/sh
# shellcheck disable=SC2016
git rebase "$@" \
--exec 'commit_date="$(git log -1 HEAD --pretty=format:"%ad")" && git log -1 HEAD && git log -1 HEAD --pretty=format:"%ad" && git commit --amend --no-edit --reset-author --date="$commit_date"'
@BenSYZ
Copy link
Author

BenSYZ commented Jan 27, 2024

In some cases, I want to reset the author and keep the date.

The reason of shellcheck disable=SC2016 is because I want to get the commit date at each rebasing step, which will give me correct date of that commit rather than set the date of each rebased commit to be the date of latest commit.

Besides, here I use "$@", so you can use --rebase or commit reference or anything you like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment