Skip to content

Instantly share code, notes, and snippets.

@kwbtdisk
Created November 26, 2017 09:05
Show Gist options
  • Save kwbtdisk/3f4b700c8c48fea6b70dd9acb5b6584c to your computer and use it in GitHub Desktop.
Save kwbtdisk/3f4b700c8c48fea6b70dd9acb5b6584c to your computer and use it in GitHub Desktop.
Change git commit time and author time
#!/usr/bin/env bash
usage() {
echo "Script for rewrite commit time"
echo 'Usage: ./gitignore_change_commit_time.sh --num 1 --time "$(date -v-46H)"'
echo " --num [NUM] ex: 3"
echo " --time [DATETIME] ex: 'Fri Nov 24 16:00:00 2017'"
exit 1
}
for OPT in "$@"
do
case "$OPT" in
'-h'|'--help' )
usage
exit 1
;;
'-v'|'--version' )
echo $VERSION
exit 1
;;
# required params
'--num' ) if [[ -z "$2" ]] || [[ "$2" =~ ^-+ ]]; then echo "$PROGNAME: option requires an argument -- $1" 1>&2; exit 1; fi
E_TAR_NUM=t;TAR_NUM="$2"; shift 2 ;;
'--time' ) if [[ -z "$2" ]] || [[ "$2" =~ ^-+ ]]; then echo "$PROGNAME: option requires an argument -- $1" 1>&2; exit 1; fi
E_DATETIME=t;DATETIME="$2"; shift 2 ;;
esac
done
# #
# check required params
# #
[ "${E_TAR_NUM}" != "t" ] && echo "param [NUM] is missing." && usage
[ "${E_DATETIME}" != "t" ] && echo "param [DATETIME] is missing." && usage
function confirm {
echo -n "Is it OK ? [y/n]"
read answer
if [ "$answer" != "y" ]; then
echo "Stoped"
exit;
fi
}
echo "You're going to exec:"
echo "$ git rebase -i HEAD~$TAR_NUM"
echo "$ git commit --amend --date=\"${DATETIME} +0900\""
echo "$ git rebase --continue"
echo "$ git rebase HEAD~$TAR_NUM --committer-date-is-author-date"
confirm
git rebase -i HEAD~$TAR_NUM
git commit --amend --date="${DATETIME} +0900"
git rebase --continue
git rebase HEAD~$TAR_NUM --committer-date-is-author-date
echo ""
echo "-----------"
echo "FINISHED:"
echo "$ git log --pretty=fuller -n $TAR_NUM"
git log --pretty=fuller -n $TAR_NUM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment