Tor*_*ger 7 git timestamp split commit rebase
如果我使用
git rebase --interactive
Run Code Online (Sandbox Code Playgroud)
我可以说,设置一行"编辑"
git reset HEAD^
git add -p
git commit -m "First part."
git commit -a -m "Second part."
Run Code Online (Sandbox Code Playgroud)
换句话说,我拆分了一个提交.不幸的是,这会为两个新提交创建当前时间戳,这使得历史看起来很有趣.有没有办法让新提交共享它分裂的时间戳?
如果您使用的是最新版本的Git,则交互式rebase期间当前正在编辑的提交的SHA1似乎存储在名为的文件中.git/rebase-merge/amend.
可以组合此信息git commit -c <commit>/--reedit-message=<commit>以在编辑器中输入新消息并保留原始作者时间戳.
那么git rebase --interactive,标记您要编辑提交,然后
git reset HEAD^
git add -p
git commit -c $(cat .git/rebase-merge/amend)
# 1. edit commit message to say "first part" (editor seeded with original message)
# 2. save and quit
git commit -a -c $(cat .git/rebase-merge/amend)
# 1. edit commit message to say "second part" (editor seeded with original message)
# 2. save and quit
Run Code Online (Sandbox Code Playgroud)
注意:如果您尝试以便携式或脚本方式执行此操作,则应使用$(git rev-parse --git-dir)而不是.git.
(感谢@torek提醒.)