git 修改时更新git commit作者日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9110310/
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
Update git commit author date when amending
提问by ksol
I found myself amending my commits quite often. I don't stash
so much because I tend to forget I did so, especially when I want to save what I did before I leave or before a weekend, so I do a "draft" commit. Only thing is, when I amend the commit, it is still set to the original author date. Is there a (simple) way to update it when amending?
我发现自己经常修改我的提交。我没有stash
那么多,因为我倾向于忘记我这样做了,特别是当我想保存我离开之前或周末之前所做的事情时,所以我做了一个“草稿”提交。唯一的问题是,当我修改提交时,它仍然设置为原始作者日期。修改时是否有(简单的)方法来更新它?
回答by Mark Longair
You can change the author date with the --date
parameter to git commit
. So, if you want to amend the last commit, and update its author date to the current date and time, you can do:
您可以使用--date
参数将作者日期更改为git commit
。因此,如果您想修改最后一次提交,并将其作者日期更新为当前日期和时间,您可以执行以下操作:
git commit --amend --date="$(date -R)"
(The -R
parameter to date
tells it to output the date in RFC 2822 format. This is one of the date formats understood by git commit
.)
(该-R
参数date
告诉它以 RFC 2822 格式输出日期。这是可以理解git commit
的日期格式之一。)
回答by Rup
Another way to do this is
另一种方法是
git commit --amend --reset-author
This does change the commit author as well as the date - but if it was originally your unpushed commit then that's a no-op.
这确实会更改提交作者以及日期 - 但如果它最初是您未推送的提交,那么这是一个无操作。
You can also add --no-edit
if you want to update the date on multiple commits but you want the commit messages to stay untouched. This way you will not be prompted to edit the message for each commit.
您还可以添加--no-edit
是否要更新多次提交的日期但希望提交消息保持不变。这样就不会提示您为每次提交编辑消息。
回答by Kamal
As of Git v2.1.4 (tested on Debian 8 (Jessie))
从 Git v2.1.4 开始(在 Debian 8 (Jessie) 上测试)
git commit --amend --date=now
回答by JLarky
I like Mark's answer and used it myself several times, but now I'm on OS X and date -R
is not supported. But everything is much easier than original answer made us think, just use empty string!
我喜欢 Mark 的回答并自己多次使用它,但现在我在 OS X 上并且date -R
不受支持。但是一切都比原始答案让我们想的要容易得多,只需使用空字符串!
git commit --date= --amend
回答by Kareem Elbahrawy
I created this npm package if someone still looking for a simple way to change dates of multiple commits.
如果有人仍在寻找一种简单的方法来更改多次提交的日期,我创建了这个 npm 包。
https://github.com/bitriddler/git-change-date
https://github.com/bitriddler/git-change-date
Usage:
用法:
npm install -g git-change-date
cd [your-directory]
git-change-date