Skip to main content Mundane Docs

Backdate Commits

This my handy script to backdate commits:

sh code snippet start

#!/bin/bash

# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
  echo "Usage: ./backdate.sh *commit-message* *datetime*"
  exit 1
fi

# Assign arguments to variables
COMMIT_MESSAGE=$1
COMMIT_DATE=$2

# Commit the staged files with the given commit message and date
GIT_COMMITTER_DATE="$COMMIT_DATE" git commit -m "$COMMIT_MESSAGE" --date="$COMMIT_DATE"

sh code snippet end