Simple shell script for changing the date of the last local commit. Useful for old projects that have been build without a version control system, but sorta have their history preserved with snapshots or something like that. 🙃 The script deliberately only focuses on the last local commit to avoid big risk with your git history.
- This script only works on the last local commit of the current branch
- This script has no effect on commits that have already been pushed
- Git for Windows
- Required for local git VCS
- Required for BASH emulation on Windows
Clone this repository with git.
git clone https://github.com/nickbeen/git-date.gitFor easy usage, create an alias for the script named e.g. git-date.
- Add file(s) to git or modify existing file(s) in your git project
- Create a new commit with a useful commit message
- Run
git-date.shto change the date of the commit
Usage: ./git-date.sh <commitDate>
Operands:
<commitDate> Date in git internal format, RFC 2822 format, ISO 8601 format or human-centric date format.The script accepts one operand, the date, in the following formats.
| Date Type | Date Format | Example |
|---|---|---|
| Git internal format | zzz | 1573821420 +0200 |
| RFC 2822 | ddd, DD MMM YYYY HH:mm:ss zzz | Fri, 15 Nov 2019 13:37:17 +0200 |
| ISO 8601 | YYYY-MM-DDTHH:mm:ss YYYY-MM-DDTHH:mm |
2019-11-15T13:13:37 2005-04-07T22:13 |
| Human-centric date formats | Yesterday last Friday at noon |
Ommiting the date will result in an error with exit code 1.
Error: operand commitDate is requiredTo run the script in Windows:
"%ProgramFiles%\Git\bin\bash.exe" git-date.sh '2019-11-15T13:37'To run the script in Linux:
./git-date.sh '2019-11-15T13:37:17'When successful, the script returns the commit log of the last commit.
commit f44e8dc0adf75b9e4df437152a6ffdfcd85cbe93 (HEAD -> master)
Author: Billy Butcher <33811927+billybutcher@users.noreply.github.com>
Date: Fri Nov 15 13:37:17 2019 +0100
Added LICENSE.md
LICENSE.md | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)Otherwise, the script will return an error message with exit code of 1.
Error: cannot amend the last commit.This script is licensed under the MIT License (MIT). See the LICENSE for more details.