如何更改一系列提交的作者?
当前回答
如果您要修复的提交是最新的,并且只有几个,您可以使用git reset和git stash的组合,在配置正确的名称和电子邮件后再次提交。
顺序如下(对于2个错误的提交,没有挂起的更改):
git config user.name <good name>
git config user.email <good email>
git reset HEAD^
git stash
git reset HEAD^
git commit -a
git stash pop
git commit -a
其他回答
如果您要修复的提交是最新的,并且只有几个,您可以使用git reset和git stash的组合,在配置正确的名称和电子邮件后再次提交。
顺序如下(对于2个错误的提交,没有挂起的更改):
git config user.name <good name>
git config user.email <good email>
git reset HEAD^
git stash
git reset HEAD^
git commit -a
git stash pop
git commit -a
如果您想(轻松)更改当前分支的作者,我会使用类似的方法:
# update author for everything since origin/master
git rebase \
-i origin/master \
--exec 'git commit --amend --no-edit --author="Author Name <author.name@email.co.uk>"'
运行git-rebase-i<sha1或起点的ref>使用edit(或e)标记要更改的所有提交循环执行以下两个命令,直到处理完所有提交:gitcommit--modify--reuse message=HEAD--author=“新作者<new@author.email>";git rebase—继续
这将保留所有其他提交信息(包括日期)。--reuse message=HEAD选项阻止消息编辑器启动。
最快、最简单的方法是使用gitrebase的--exec参数:
git rebase -i -p --exec 'git commit --amend --reset-author --no-edit'
这将创建如下所示的待办事项列表:
pick ef11092 Blah blah blah
exec git commit --amend --reset-author --no-edit
pick 52d6391 Blah bloh bloo
exec git commit --amend --reset-author --no-edit
pick 30ebbfe Blah bluh bleh
exec git commit --amend --reset-author --no-edit
...
这将自动运行,当您有数百次提交时,这将正常运行。
对于windows下的用户,也可以使用git火箭过滤器工具。
根据文档:
更改提交作者姓名和电子邮件:
git-rocket-filter --branch TestBranch --commit-filter '
if (commit.AuthorName.Contains("Jim")) {
commit.AuthorName = "Paul";
commit.AuthorEmail = "paul@company.com";
}
推荐文章
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- 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':没有这样的文件或目录