git commit --date 参数的格式是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19742345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the format for --date parameter of git commit
提问by v010dya
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 提交的日期,所有文档都指向 --date 参数,但随后留下一个没有适当格式的线索。我已经尝试了我能想到的每一种排列,但每一种排列都出现“致命:无效日期格式:”错误。
回答by VonC
Git 2.6+ (Q3 2015) add a new option.
Git 2.6+(2015 年第三季度)添加了一个新选项。
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)
请参阅Jeff King ( ) 的commit e4f031e(2015 年 6 月 30 日)和commit aa1462c、commit a5481a6、commit b7c1e11(2015 年 6 月 25 日)。(由Junio C Hamano合并-- --在d939af1 提交中,2015 年 8 月 3 日)peff
gitster
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.
引入“格式化”日期模式
这将格式直接提供给
strftime
.
除了稍微灵活一点之外,主要优点是您的系统strftime
可以更多地了解您的语言环境的首选格式(例如,如何拼写星期几)。
--date=format:...
将格式提供...
给您的系统strftime
。
用于--date=format:%c
以系统区域设置的首选格式显示日期。
有关strftime
格式占位符的完整列表,请参阅手册。
Davide Cavestroproposes in the commentsthe example:
Davide Cavestro在评论中提出了这个例子:
git commit -m "Test" --date=format:relative:5.hours.ago
Original answer (mid 2014)
原始答案(2014 年中)
The --date
option (introduced in commit 02b47cdin Dec. 2009, for git1.7.0) uses the same format than for GIT_AUTHOR_DATE
, with date formats tested in commit 96b2d4f:
该--date
选项(在2009 年 12 月的commit 02b47cd中引入,用于 git1.7.0)使用与 for 相同的格式GIT_AUTHOR_DATE
,日期格式在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
- RFC2822:
Mon, 3 Jul 2006 17:18:43 +0200
- ISO8601:
2006-07-03 17:18:43 +0200
- 当地的:
Mon Jul 3 15:18:43 2006
- 简短:(
2006-07-03
不在 1.9.1 中,在 2.3.0 中有效) 相对:见提交 34dc6e7:
5.seconds.ago, 2.years.3.months.ago, '6am yesterday'
原始:请参阅提交 7dff9b3(git 1.6.2,2009年 3 月)
内部原始 git 格式 - 自纪元加时区以来的秒数(换
一种方式:'date +"%s %z"
' 格式)- 默认:
Mon Jul 3 17:18:43 2006 +0200
ADTCasks and answers in the comments:
Does it accept 2006-07-03 15:18:43 for local?
本地是否接受 2006-07-03 15:18:43 ?
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).
是的,它确实有效,并且会自动采用本地时区。
与该格式我不需要理会它是一周中的哪一天(Sun
,Mon
,等)。
回答by Dmytro Melnychuk
Simple example:
简单的例子:
GIT_AUTHOR_DATE='2015-04-19 17:18:43 +0200' GIT_COMMITTER_DATE='2015-04-19 17:18:43 +0200' git commit -m 'Commit message'