如何在 git 中的第一次提交时修复元信息?

Cha*_*ens 7 git

这是与如何编辑 git 的历史记录以更正不正确的电子邮件地址/名称相关的问题。使用git rebase -i <first commit>, git commit --amend --author "Foo <foo@example.com>", 和git rebase --continue,我能够修复除第一个提交之外的所有提交的日志。如何修复第一次提交?

pjz*_*pjz 13

经过多次反复试验,发现以下配方有效:

# tag the root-most commit so we can reference it
git tag root `git rev-list HEAD | tail -1`
# check it out on its own branch
git checkout -b new-root root
# amend the commit
git commit --amend
# now you've changed the commit message, so checkout the original branch again
git checkout @{-1}
# and rebase it onto your new root commit
git rebase --onto new-root root
# then nuke the temporary branch and tag we created
git branch -d new-root
git tag -d root
Run Code Online (Sandbox Code Playgroud)

对于这个答案,真正的功劳应该归功于 #git 上的 drizzd。