Update git commit author date when amending

后端 未结 5 1493
北恋
北恋 2020-12-12 08:48

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 lea

相关标签:
5条回答
  • 2020-12-12 09:19

    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:

    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.)

    0 讨论(0)
  • 2020-12-12 09:19

    As of Git v2.1.4 (tested on Debian 8 (Jessie))

    git commit --amend --date=now
    
    0 讨论(0)
  • 2020-12-12 09:25

    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.

    0 讨论(0)
  • 2020-12-12 09:33

    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!

    git commit --date= --amend
    
    0 讨论(0)
  • 2020-12-12 09:41

    I created this npm package if someone still looking for a simple way to change dates of multiple commits.

    https://github.com/bitriddler/git-change-date

    Usage:

    npm install -g git-change-date
    cd [your-directory]
    git-change-date
    
    0 讨论(0)
提交回复
热议问题