Skip to content

Commit 02b47cd

Browse files
Miklos Vajnagitster
authored andcommitted
builtin-commit: add --date option
This is like --author: allow a user to specify a given date without using the GIT_AUTHOR_DATE environment variable. Signed-off-by: Miklos Vajna <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b809d9c commit 02b47cd

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Documentation/git-commit.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ SYNOPSIS
1111
'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
1212
[(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
1313
[--allow-empty] [--no-verify] [-e] [--author=<author>]
14-
[--cleanup=<mode>] [--] [[-i | -o ]<file>...]
14+
[--date=<date>] [--cleanup=<mode>] [--] [[-i | -o ]<file>...]
1515

1616
DESCRIPTION
1717
-----------
@@ -85,6 +85,9 @@ OPTIONS
8585
an existing commit that matches the given string and its author
8686
name is used.
8787

88+
--date=<date>::
89+
Override the author date used in the commit.
90+
8891
-m <msg>::
8992
--message=<msg>::
9093
Use the given <msg> as the commit message.

builtin-commit.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static char *edit_message, *use_message;
5252
static char *author_name, *author_email, *author_date;
5353
static int all, edit_flag, also, interactive, only, amend, signoff;
5454
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
55-
static char *untracked_files_arg;
55+
static char *untracked_files_arg, *force_date;
5656
/*
5757
* The default commit message cleanup mode will remove the lines
5858
* beginning with # (shell comments) and leading and trailing
@@ -90,6 +90,7 @@ static struct option builtin_commit_options[] = {
9090

9191
OPT_FILENAME('F', "file", &logfile, "read log from file"),
9292
OPT_STRING(0, "author", &force_author, "AUTHOR", "override author for commit"),
93+
OPT_STRING(0, "date", &force_date, "DATE", "override date for commit"),
9394
OPT_CALLBACK('m', "message", &message, "MESSAGE", "specify commit message", opt_parse_m),
9495
OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit"),
9596
OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"),
@@ -410,6 +411,9 @@ static void determine_author_info(void)
410411
email = xstrndup(lb + 2, rb - (lb + 2));
411412
}
412413

414+
if (force_date)
415+
date = force_date;
416+
413417
author_name = name;
414418
author_email = email;
415419
author_date = date;

t/t7501-commit.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,21 @@ test_expect_success 'amend commit to fix author' '
211211
212212
'
213213

214+
test_expect_success 'amend commit to fix date' '
215+
216+
test_tick &&
217+
newtick=$GIT_AUTHOR_DATE &&
218+
git reset --hard &&
219+
git cat-file -p HEAD |
220+
sed -e "s/author.*/author $author $newtick/" \
221+
-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
222+
expected &&
223+
git commit --amend --date="$newtick" &&
224+
git cat-file -p HEAD > current &&
225+
test_cmp expected current
226+
227+
'
228+
214229
test_expect_success 'sign off (1)' '
215230
216231
echo 1 >positive &&

0 commit comments

Comments
 (0)