Git批量修改历史commit中的user.name 和user.email
2017-01-06 00:00
706 查看
内容收藏在此Git常用命令清单.md
1.克隆仓库
注意参数,这个不是普通的clone,clone下来的仓库并不能参与开发
git clone --bare https://github.com/user/repo.git cd repo.git
2.命令行中运行代码
OLD_EMAIL原来的邮箱
CORRECT_NAME更正的名字
CORRECT_EMAIL更正的邮箱
将下面代码复制放到命令行中执行
git filter-branch -f --env-filter ' OLD_EMAIL="wowohoo@qq.com" CORRECT_NAME="小弟调调" CORRECT_EMAIL="更正的邮箱@qq.com" if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] then export GIT_COMMITTER_NAME="$CORRECT_NAME" export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" fi if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] then export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" fi ' --tag-name-filter cat -- --branches --tags
执行过程
Rewrite 160d4df2689ff6df3820563bfd13b5f1fb9ba832 (479/508) (16 seconds passed, remaining 0 predicted) Ref 'refs/heads/dev' was rewritten Ref 'refs/heads/master' was rewritten
3.同步到远程仓库
同步到push远程git仓库
git push --force --tags origin 'refs/heads/*'
我还遇到了如下面错误,lab默认给master分支加了保护,不允许强制覆盖。Project(项目)
->Setting
->Repository
菜单下面的Protected branches
把master的保护去掉就可以了。修改完之后,建议把master的保护再加回来,毕竟强推不是件好事。
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
当上面的push 不上去的时候,先 git pull
确保最新代码
git pull --allow-unrelated-histories # 或者指定分枝 git pull origin master --allow-unrelated-histories
相关文章推荐
- git修改user.name和user.email后找回之前的commit
- git修改user.name和user.email
- 如何修改git全局初始化的用户名和邮箱? (git修改user.name 和user.email)
- git修改user.name和user.email
- git下修改已经提交N次代码的user.name和user.email
- Git之user.name&user.email配置的影响及修改+备份工作成果
- Git在提交的时候:user name and email must be set brfore commit.
- git bash笔记-配置/修改git的user.name/email
- 如何修改git全局初始化的用户名和邮箱? (git修改user.name 和user.email)
- git提交错误 git config --global user.email "you@example.com" git config --global user.name "Your Name
- git修改已初始化配置过的user.name
- git修改name和email
- Git查看并修改name和email
- git修改name和email
- git commit Please tell me who you are it config --global user.email "you@example.com"
- GIT 初始化 user.name user.email
- git查看commit历史,某次commit修改内容,指定文件修改历史
- git查看commit修改历史详情
- Git 初始化全局user.name 和 user.email
- Git批量修改提交历史