内容简介:有时候,公司提交的代码必须使用公司邮箱,而你误操作,直接把自己个人邮箱提交上去了,此时你就会遇到这样的需求:如何修改git已提交的邮箱?而这个需求对于新手来说,往往要花费半天的时间才能理解修改过程,简直太傻比了,所以我这里做一个详细的文档来帮助自己和你搞清楚这个流程。尤其要理解变基,它不是一个命令执行就完成了,而是一连串命令的组合。执行后,会打开最近一条的提交记录,当然上面的命令可以指定某一条记录,命令是:
有时候,公司提交的代码必须使用公司邮箱,而你误操作,直接把自己个人邮箱提交上去了,此时你就会遇到这样的需求:如何修改git已提交的邮箱?
而这个需求对于新手来说,往往要花费半天的时间才能理解修改过程,简直太傻比了,所以我这里做一个详细的文档来帮助自己和你搞清楚这个流程。尤其要理解变基,它不是一个命令执行就完成了,而是一连串命令的组合。
步骤1:变基
git rebase -i
执行后,会打开最近一条的提交记录,当然上面的命令可以指定某一条记录,命令是:
git rebase -i "your commit id"
对于sourcetree用户来说,commit id是SHA-1,可以右键某条提交记录,选择菜单"复制SHA-1到剪贴板",如下图:
变基rebase命令执行完成后,会打印 类似 如下内容:
pick bd81df5 更新API # Rebase abcb9d0..bd81df5 onto abcb9d0 (1 command) # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # d, drop = remove commit # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out
新手往往会一脸懵逼,不止所错,此时是在rebase的过程中,你需要把pick改为edit,如下:
edit bd81df5 更新API # Rebase abcb9d0..bd81df5 onto abcb9d0 (1 command) # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # d, drop = remove commit # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out
更改完成后,保存并退出vi编辑器: :wq
然后会打印这样的消息:
chengmingdeMacBook-Pro:server cmlanche$ git rebase -i "abcb9d0d1e99cdad25d8d08119e494436b000e59" Stopped at bd81df5... 更新API You can amend the commit now, with git commit --amend Once you are satisfied with your changes, run git rebase --continue chengmingdeMacBook-Pro:server cmlanche$
给大家先科普一下这个 amend 英文单词,是修改的意思,对我来说好陌生,为啥不用change或者fix之类的。
上面的信息说了,如果你要amend,也就是要修改这个提交的话,那么用
git commit --amend
如果你对这次修改满意的话,就用如下命令结束此次变基
git rebase --continue
重置账户邮箱信息
我们当然要修改啦,那么执行如下命令,重置提交的账户信息:
git commit --amend --author="cmlanche <1204833748@qq.com>" --no-edit
同事,要注意你的sourcetree,出现了新情况!
我们可以看到一个新的提交,并且,邮箱账号都经过了修改,如果你去掉 --no-edit 还可以修改commit message,也就是图中的"更新API",举栗子吧,我可以继续用amend修改此次变基
git commit --amend --author="cmlanche <1204833748@qq.com>"
保存退出vi编辑器,看sourcetree咋样了:
真的很完美,接下来就是合并了,退出变基。
退出变基
git rebase --continue
在控制台中打印如上命令退出变基,我们看到退出变基也就是使用最新的修改了,就一条分支了。
chengmingdeMacBook-Pro:server cmlanche$ git rebase --continue Successfully rebased and updated refs/heads/bulma.
最后总结一下
变基真的很有用,他不是一条命令搞定的,是一个过程,就像变成中打开了一个输入流,最后用完你得关闭输入流一样。
通过变基你可以轻松实现提交信息的任意重新修改!
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 如果修改 git 已提交的用户邮箱和用户名
- 在整个 Git 仓库的历史(包括所有分支和标签)中修改提交作者的信息(姓名和邮箱)
- Zabbix服务器设置邮箱报警
- C# 使用 QQ 邮箱发送邮件
- 让 QQ 邮箱更好用,支持桌面通知
- swpu ctf 有趣的邮箱注册 详细题解
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
大数据供应链
娜达·R·桑德斯 (Nada R. Sanders) / 丁晓松 / 中国人民大学出版社 / 2015-7-1 / CNY 55.00
第一本大数据供应链落地之道的权威著作,全球顶级供应链管理专家娜达·桑德斯博士聚焦传统供应链模式向大数据转型,助力工业4.0时代智能供应链构建。 在靠大数据驱动供应链处于领先地位的企业中,45% 是零售商,如沃尔玛、亚马逊,而22%是快消企业,如戴尔电脑。他们都前所未有地掌控了自己的供应链。在库存管理、订单履行率、原材料和产品交付上具有更为广阔的视野。利用具有预见性的大数据分析结果,可以使供需......一起来看看 《大数据供应链》 这本书的介绍吧!