- git commit的--date参数的格式是什么? [英] What is the format for --date parameter of git commit
问题描述
我需要覆盖git提交的日期,所有文档指向--date参数,但是会留下一个不知道适当格式的线索。我已经尝试了所有我能想到的排列方式,并且每个人都会遇到致命的:无效的日期格式:错误。
/ div> Git 2.6+(2015年第3季度)添加了一个新选项。
请参阅 commit e4f031e (2015年6月30日)和提交aa1462c ,提交a5481a6 ,提交b7c1e11 (2015年6月25日)由 Jeff King( peff
)。
(由 Junio C Hamano - gitster
- 在提交d939af1 ,2015年8月3日)
介绍格式日期模式
这直接将格式提供给
strftime
。
除了更灵活一点外,主要优点是您的系统
strftime
可能会了解您的语言环境的首选格式(例如,如何拼写星期几)。
- date = format:...
将格式...
提供给您的系统strftime
。
使用- date =格式:%c
系统区域设置的首选格式。
请参阅strftime
手册以获取格式占位符的完整列表。
Davide Cavestro 在评论中提出 例子:
git commit -mTest--date = format:relative:5.hours.ago
原始答案(2014年中)
- 日期
选项(介绍于 2009年12月提交02b47cd ,对于git1.7.0)使用与 GIT_AUTHOR_DATE
相同的格式,日期格式在< A HREF = https://github.com/git/git/commit/96b2d4fa927c5055adc5b1d08f10a5d7352e2989 相对= nofollow noreferrer>提交96b2d4f :
有您可以看到接受的各种格式: relative:参见提交34dc6e7 : 生:请参阅提交7dff9b3 (GIT 1.6 .2,2009年3月)
2006年7月3日星期一17:18:43 +0200
2006-07-03 17:18:43 +0200
Mon Jul 3 15:18:43 2006
2006 -07-03
(不在1.9.1中,在2.3.0中有效)
5.seconds.ago,
2.years.3.months.ago,
'昨天早上6点'
内部原始git格式 - 自时代以来加秒数时区
(换句话说:' date +%s%z
'格式)
Mon Jul 3 17:18:43 2006 +0200
是否接受2006- 07-03 15:18:43 for local?
是它可以工作,它会自动获取本地时区。
以这种格式,我不需要打扰一周中的哪一天(Sun
,Mon
等)。
I need to overwrite the date of the commit of git, all the documentation points to --date parameter, but then leaves one without a clue to the appropriate format. I've tried every permutation i can think of, and i'm getting "fatal: invalid date format:" error for each and every one.
Git 2.6+ (Q3 2015) add a new option.
See commit e4f031e (30 Jun 2015), and commit aa1462c, commit a5481a6, commit b7c1e11 (25 Jun 2015) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
-- in commit d939af1, 03 Aug 2015)
introduce "format" date-mode
This feeds the format directly to
strftime
.
Besides being a little more flexible, the main advantage is that your systemstrftime
may know more about your locale's preferred format (e.g., how to spell the days of the week).
--date=format:...
feeds the format...
to your systemstrftime
.
Use--date=format:%c
to show the date in your system locale's preferred format.
See thestrftime
manual for a complete list of format placeholders.
Davide Cavestro proposes in the comments the example:
git commit -m "Test" --date=format:relative:5.hours.ago
Original answer (mid 2014)
The --date
option (introduced in commit 02b47cd in Dec. 2009, for git1.7.0) uses the same format than for GIT_AUTHOR_DATE
, with date formats tested in commit 96b2d4f:
There you can see the various format accepted:
- rfc2822:
Mon, 3 Jul 2006 17:18:43 +0200
- iso8601:
2006-07-03 17:18:43 +0200
- local:
Mon Jul 3 15:18:43 2006
- short:
2006-07-03
(not in 1.9.1, works in 2.3.0) relative: see commit 34dc6e7:
5.seconds.ago, 2.years.3.months.ago, '6am yesterday'
raw: see commit 7dff9b3 (git 1.6.2, March 2009)
internal raw git format - seconds since epoch plus timezone
(put another way: 'date +"%s %z"
' format)- default:
Mon Jul 3 17:18:43 2006 +0200
ADTC asks and answers in the comments:
Does it accept 2006-07-03 15:18:43 for local?
Yes it does work and it takes the local time zone automatically.
With that format I don't need to bother which day of the week it is (Sun
,Mon
, etc).
这篇关于 - git commit的--date参数的格式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!