如何更改一系列提交的作者?
当前回答
这不是对你问题的回答,而是一个脚本,你可以用它来避免将来发生这种情况。它利用Git 2.9版以来可用的全局钩子,根据您所在的目录检查您的电子邮件配置:
#!/bin/sh
PWD=`pwd`
if [[ $PWD == *"Ippon"* ]] # 1)
then
EMAIL=$(git config user.email)
if [[ $EMAIL == *"Work"* ]] # 2)
then
echo "";
else
echo "Email not configured to your Work email in the Work directory.";
git config user.email "youremail@youremail.com"
echo "Git email configuration has now been changed to \"$(git config user$
echo "\nPlease run your command again..."
echo ''
exit 1
fi;
elif [[ $PWD == *"Personal"* ]]
then
EMAIL=$(git config user.email)
if [[ $EMAIL == "youremail@youremail.com" ]]
then
echo "";
else
echo "Email is not configured to your personal account in the Personal di$
git config user.email "youremail@youremail.com"
echo "Git email configuration has now been changed to \"$(git config user$
echo "\nPlease run your command again..."
echo ''
exit 1;
fi;
fi;
它检查您当前的工作目录,然后验证您的git是否配置为正确的电子邮件。如果没有,它会自动更改。请在此处查看详细信息。
其他回答
git rebase -i YOUR_FIRTS_COMMIT_SHA^
while true; do git commit --amend --author="Name Surname <email@example.com>" --no-edit && git rebase --continue; done
在重基完成后按^C#(循环将继续更新上次提交)
使用交互式rebase,您可以在每次提交后放置一个修改命令。例如:
pick a07cb86 Project tile template with full details and styling
x git commit --amend --reset-author -Chead
以上所有答案都改写了存储库的历史。只要要更改的名称未被多个作者使用,特别是如果存储库已共享且提交已过时,我更愿意使用.mailmap,记录在https://git-scm.com/docs/git-shortlog.它允许将不正确的名称/电子邮件映射到正确的名称,而无需修改回购历史记录。您可以使用以下行:
Proper Name <proper@email.xx> <root@localhost>
对于重置当前用户和当前时间戳的所有提交(包括首次提交):
git rebase --root --exec "git commit --amend --no-edit --date 'now' --reset-author"
对于所有提交,我的解决方案:
git rebase -i --root -x "git commit --amend --author 'bedorlan <bedorlan@gmail.com>' --no-edit"
推荐文章
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别
- GitHub -致命:无法读取用户名https://github.com':没有这样的文件或目录
- 撤消git平分错误
- 使用.gitconfig配置diff工具