如何更改一系列提交的作者?
当前回答
您可以将其用作别名,以便执行以下操作:
git change-commits GIT_AUTHOR_NAME "old name" "new name"
或最近10次提交:
git change-commits GIT_AUTHOR_EMAIL "old@email.com" "new@email.com" HEAD~10..HEAD
添加到~/.gitconfig:
[alias]
change-commits = "!f() { VAR=$1; OLD=$2; NEW=$3; shift 3; git filter-branch --env-filter \"if [[ \\\"$`echo $VAR`\\\" = '$OLD' ]]; then export $VAR='$NEW'; fi\" $@; }; f "
资料来源:https://github.com/brauliobo/gitconfig/blob/master/configs/.gitconfig
希望它有用。
其他回答
最快、最简单的方法是使用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
...
这将自动运行,当您有数百次提交时,这将正常运行。
试试看。它将执行与上述相同的操作,但以交互方式执行。
bash <(curl -s https://raw.githubusercontent.com/majdarbash/git-author-change-script/master/run.sh)
参考:https://github.com/majdarbash/git-author-change-script
运行git-rebase-i<sha1或起点的ref>使用edit(或e)标记要更改的所有提交循环执行以下两个命令,直到处理完所有提交:gitcommit--modify--reuse message=HEAD--author=“新作者<new@author.email>";git rebase—继续
这将保留所有其他提交信息(包括日期)。--reuse message=HEAD选项阻止消息编辑器启动。
如果您要修复的提交是最新的,并且只有几个,您可以使用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 filter-branch --tag-name-filter cat --env-filter "
export GIT_AUTHOR_NAME='New name';
export GIT_AUTHOR_EMAIL='New email'
" -- --all
然后,如过滤器分支的MAN页面所述,删除过滤器分支备份的所有原始引用(这是破坏性的,首先备份):
git for-each-ref --format="%(refname)" refs/original/ | \
xargs -n 1 git update-ref -d
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别