如何更改一系列提交的作者?
当前回答
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#(循环将继续更新上次提交)
其他回答
最快、最简单的方法是使用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
...
这将自动运行,当您有数百次提交时,这将正常运行。
如果您想(轻松)更改当前分支的作者,我会使用类似的方法:
# 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>"'
这是@Brian版本的更详细版本:
要更改作者和提交人,可以执行以下操作(在bash中可以使用换行符):
git filter-branch --env-filter '
if [ "$GIT_COMMITTER_NAME" = "<Old name>" ];
then
GIT_COMMITTER_NAME="<New name>";
GIT_COMMITTER_EMAIL="<New email>";
GIT_AUTHOR_NAME="<New name>";
GIT_AUTHOR_EMAIL="<New email>";
fi' -- --all
您可能会遇到以下错误之一:
临时目录已存在以Refs/original开头的引用已存在(这意味着先前在存储库上运行了另一个过滤器分支,然后在refs/original处备份原始分支引用)
如果要在出现这些错误的情况下强制运行,请添加--force标志:
git filter-branch --force --env-filter '
if [ "$GIT_COMMITTER_NAME" = "<Old name>" ];
then
GIT_COMMITTER_NAME="<New name>";
GIT_COMMITTER_EMAIL="<New email>";
GIT_AUTHOR_NAME="<New name>";
GIT_AUTHOR_EMAIL="<New email>";
fi' -- --all
可能需要对--all选项做一点解释:它使过滤器分支可以处理所有引用(包括所有分支)的所有修订。例如,这意味着标记也被重写,并且在重写的分支上可见。
一个常见的“错误”是使用HEAD,这意味着只过滤当前分支上的所有修订。然后,重写的分支中不存在标记(或其他引用)。
使用交互式rebase,您可以在每次提交后放置一个修改命令。例如:
pick a07cb86 Project tile template with full details and styling
x git commit --amend --reset-author -Chead
对于重置当前用户和当前时间戳的所有提交(包括首次提交):
git rebase --root --exec "git commit --amend --no-edit --date 'now' --reset-author"
推荐文章
- 如何将git配置存储为存储库的一部分?
- 如何修改GitHub拉请求?
- 如何在Github和本地删除最后n次提交?
- 我如何调试git/git-shell相关的问题?
- 错误:无法使用rebase进行拉取:您有未分阶段的更改
- Git隐藏未缓存:如何把所有未分期的变化?
- 真实的恶魔
- 如何从另一个分支获得更改
- Git:权限被拒绝(publickey)致命-无法从远程存储库读取。克隆Git存储库时
- git reflog和log有什么区别?
- git推挂在Total line之后
- 重命名git子模块
- 结合Git存储库的前两次提交?
- Xcode 6 gitignore文件应该包括什么?
- 我如何从现有回购的分支创建一个新的GitHub回购?