修改git已提交的的author和email
2015-07-28 14:36
681 查看
转自:http://lmbj.net/blog/how-do-i-change-the-author-of-a-commit-in-git/
这个问题来源于我的实际应用中的需求,在得问发起提问:修改git已提交的的author和email,具体如下:
修改上一次提交的用户名和Email可以用以下命令:
git commit –amend –author=’Your Name you@example.com’
我现在的需求是这样的:项目中git初始化时未指定name和email,使用了全局的name和email设置,已经提交过N次,假设10次。但是我希望这个项目使用自己的name和email,而不是全局的。那么该如何修改N次已提交的name和email?
我明确的知道肯定有这样一个操作,可以一次完成,但是苦于不知道这是怎样一个操作。有兄弟回答,给出答案:git filter-branch,大概明白了意思,感觉要写一个脚本,但是只是用过简单的git命令,自己写不出,然后顺着这个方向找,找到 http://stackoverflow.com/questions/750172/how-do-i-change-the-author-of-a-commit-in-git。可以说是一模一样的需求(怎么没想到用英文搜索答案??估计想到,也拼装不出这句吧?)。这里的答案给出了具体的脚本,其中github上的http://help.github.com/articles/changing-author-info 解决方案比较完美,或者说扩展了这个需求,不仅仅解决这个问题。以下是实现代码:
这个问题来源于我的实际应用中的需求,在得问发起提问:修改git已提交的的author和email,具体如下:
修改上一次提交的用户名和Email可以用以下命令:
git commit –amend –author=’Your Name you@example.com’
我现在的需求是这样的:项目中git初始化时未指定name和email,使用了全局的name和email设置,已经提交过N次,假设10次。但是我希望这个项目使用自己的name和email,而不是全局的。那么该如何修改N次已提交的name和email?
我明确的知道肯定有这样一个操作,可以一次完成,但是苦于不知道这是怎样一个操作。有兄弟回答,给出答案:git filter-branch,大概明白了意思,感觉要写一个脚本,但是只是用过简单的git命令,自己写不出,然后顺着这个方向找,找到 http://stackoverflow.com/questions/750172/how-do-i-change-the-author-of-a-commit-in-git。可以说是一模一样的需求(怎么没想到用英文搜索答案??估计想到,也拼装不出这句吧?)。这里的答案给出了具体的脚本,其中github上的http://help.github.com/articles/changing-author-info 解决方案比较完美,或者说扩展了这个需求,不仅仅解决这个问题。以下是实现代码:
#!/bin/sh git filter-branch --env-filter ' an="$GIT_AUTHOR_NAME" am="$GIT_AUTHOR_EMAIL" cn="$GIT_COMMITTER_NAME" cm="$GIT_COMMITTER_EMAIL" if [ "$GIT_COMMITTER_EMAIL" = "your@email.to.match" ] then cn="Your New Committer Name" cm="Your New Committer Email" fi if [ "$GIT_AUTHOR_EMAIL" = "your@email.to.match" ] then an="Your New Author Name" am="Your New Author Email" fi export GIT_AUTHOR_NAME="$an" export GIT_AUTHOR_EMAIL="$am" export GIT_COMMITTER_NAME="$cn" export GIT_COMMITTER_EMAIL="$cm" '
相关文章推荐
- http://blog.csdn.net/jiajiayouba/article/details/9083757#comments
- ( linker command failed with exit code 1)错误总结
- samba错误:session setup failed: NT_STATUS_LOGON_FAILURE
- Async/Await 最佳做法
- service中AIDL的应用
- 2015 Multi-University Training Contest 3--1011 Work
- 那些没有root权限的岁月:一分钟解决mutt No mailbox
- UVa 576 - Haiku Review
- Scan IP relocate/failover其它段后不能ping通过
- HDU 1022 Train Problem I 【栈】
- no version information available
- rails之distance_of_time_in_words等显示时间差大概描述的方法
- 【POJ 1151】Air Raid
- Contains Duplicate III
- HTTP请求报文和HTTP响应报文 http://blog.csdn.net/zhangliang_571/article/details/23508953
- HDU 4630 No Pain No Game (线段树离线查询)
- 在rails的console下调用helper方法
- RAID详解[RAID0/RAID1/RAID10/RAID5]
- 对pair元素进行排序
- 用GDB调试程序 http://blog.csdn.net/dadalan/article/details/3758025