Skip to content

Commit 762c710

Browse files
committed
Merge branch 'mv/commit-date'
* mv/commit-date: Document date formats accepted by parse_date() builtin-commit: add --date option
2 parents 79f6ce5 + 788070a commit 762c710

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

Documentation/date-formats.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
DATE FORMATS
2+
------------
3+
4+
The GIT_AUTHOR_DATE, GIT_COMMITTER_DATE environment variables
5+
ifdef::git-commit[]
6+
and the `--date` option
7+
endif::git-commit[]
8+
support the following date formats:
9+
10+
Git internal format::
11+
It is `<unix timestamp> <timezone offset>`, where `<unix
12+
timestamp>` is the number of seconds since the UNIX epoch.
13+
`<timezone offset>` is a positive or negative offset from UTC.
14+
For example CET (which is 2 hours ahead UTC) is `+0200`.
15+
16+
RFC 2822::
17+
The standard email format as described by RFC 2822, for example
18+
`Thu, 07 Apr 2005 22:13:13 +0200`.
19+
20+
ISO 8601::
21+
Time and date specified by the ISO 8601 standard, for example
22+
`2005-04-07T22:13:13`. The parser accepts a space instead of the
23+
`T` character as well.
24+
+
25+
NOTE: In addition, the date part is accepted in the following formats:
26+
`YYYY.MM.DD`, `MM/DD/YYYY` and `DD.MM.YYYY`.

Documentation/git-commit-tree.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ A commit comment is read from stdin. If a changelog
7373
entry is not provided via "<" redirection, 'git-commit-tree' will just wait
7474
for one to be entered and terminated with ^D.
7575

76+
include::date-formats.txt[]
7677

7778
Diagnostics
7879
-----------

Documentation/git-commit.txt

Lines changed: 6 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
-----------
@@ -99,6 +99,9 @@ OPTIONS
9999
an existing commit that matches the given string and its author
100100
name is used.
101101

102+
--date=<date>::
103+
Override the author date used in the commit.
104+
102105
-m <msg>::
103106
--message=<msg>::
104107
Use the given <msg> as the commit message.
@@ -231,6 +234,8 @@ specified.
231234
these files are also staged for the next commit on top
232235
of what have been staged before.
233236

237+
:git-commit: 1
238+
include::date-formats.txt[]
234239

235240
EXAMPLES
236241
--------

builtin-commit.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static char *edit_message, *use_message;
5353
static char *author_name, *author_email, *author_date;
5454
static int all, edit_flag, also, interactive, only, amend, signoff;
5555
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
56-
static char *untracked_files_arg;
56+
static char *untracked_files_arg, *force_date;
5757
/*
5858
* The default commit message cleanup mode will remove the lines
5959
* beginning with # (shell comments) and leading and trailing
@@ -98,6 +98,7 @@ static struct option builtin_commit_options[] = {
9898
OPT_GROUP("Commit message options"),
9999
OPT_FILENAME('F', "file", &logfile, "read log from file"),
100100
OPT_STRING(0, "author", &force_author, "AUTHOR", "override author for commit"),
101+
OPT_STRING(0, "date", &force_date, "DATE", "override date for commit"),
101102
OPT_CALLBACK('m', "message", &message, "MESSAGE", "specify commit message", opt_parse_m),
102103
OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit"),
103104
OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"),
@@ -441,6 +442,9 @@ static void determine_author_info(void)
441442
email = xstrndup(lb + 2, rb - (lb + 2));
442443
}
443444

445+
if (force_date)
446+
date = force_date;
447+
444448
author_name = name;
445449
author_email = email;
446450
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)