当前位置: 首页 > news >正文

Changing Your Commit Messages

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

This document describes how to modify commit messages in Git after the fact.

Changing the Last Commit Message

If you only want to modify your last commit message, it is very simple. Just run

$ git commit --amend

That will drop you into your text exitor and let you change the last commit message.

Changing Multiple Commit Messages

Now let's assume that you want to modify either multiple commit messages, or a commit message several commits back. In this case, you need to use a tool called 'interactive rebase'. You can run this with the -i option to git rebase. You will need to supply how far back you want to rewrite commits by telling it which commit to go back to.

If you want to change the last 3 commit messages, or any of the commit messages up to that point, supply 'HEAD~3' to the git rebase -i command.

$ git rebase -i HEAD~3

Warning: every commit you see in this list will be re-written, whether you change the message or not. Do not include any commit you have already pushed to a central server - it will mess other people up.

Running this command will give you a list of commits in your text editor that looks something like this:

pick dd56df4 so the reference updates
pick 36c7dba updated ticgit gem
pick 7482e0d updated the gemspec to hopefully work better

# Rebase b429ad8..7482e0d onto b429ad8
#
# Commands:
#  p, pick = use commit
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

Change the word 'pick' to the work 'edit' for each of the commits you want to change the message for. For example, let's say we want to change the third commit message only, we would change the file to look like this

pick dd56df4 so the reference updates
pick 36c7dba updated ticgit gem
edit 7482e0d updated the gemspec to hopefully work better

When you save and exit the editor, it will rewind you back to that last commit in that list and drop you on the command line with the following message:

$ git rebase -i HEAD~3
Stopped at 7482e0d... updated the gemspec to hopefully work better
You can amend the commit now, with

	git commit --amend

Once you are satisfied with your changes, run

	git rebase --continue

These instructions tell you exactly what to do. Type

$ git commit --amend

Change the commit message and exit the editor. Then run

$ git rebase --continue

You can repeat those steps for each commit you changed to edit. Each time it will stop and let you amend the commit and continue when you're done. In this case, we had no other 'edit's so it will simply rebase the rest of the commits and we're done!

转载于:https://my.oschina.net/legend1989/blog/793344

相关文章:

  • mybatis对java自定义注解的使用——入门篇
  • 垃圾收集器之:CMS收集器
  • JAVA8之lambda表达式详解,及stream中的lambda使用
  • android中aar文件
  • Linux Increase The Maximum Number Of Open Files / File Descriptors (FD)
  • iOS10 UI教程层次结构的事件
  • WebAPi的可视化输出模式(RabbitMQ、消息补偿相关)所有webapi似乎都缺失的一个功能...
  • 请设计一个一百亿的计算器
  • 润乾报表查看系统字体的方法
  • git初级--配置
  • C++11:POD数据类型
  • ListMultimap 容器
  • 【转载】MacOS软件包管理工具-HomeBrew
  • centos系统启动故障之MBR扇区故障
  • 求绝对值
  • @angular/forms 源码解析之双向绑定
  • 【RocksDB】TransactionDB源码分析
  • CSS 专业技巧
  • iOS帅气加载动画、通知视图、红包助手、引导页、导航栏、朋友圈、小游戏等效果源码...
  • JavaScript设计模式系列一:工厂模式
  • k个最大的数及变种小结
  • NLPIR语义挖掘平台推动行业大数据应用服务
  • npx命令介绍
  • PV统计优化设计
  • Python利用正则抓取网页内容保存到本地
  • Spark RDD学习: aggregate函数
  • Yeoman_Bower_Grunt
  • 工作踩坑系列——https访问遇到“已阻止载入混合活动内容”
  • 互联网大裁员:Java程序员失工作,焉知不能进ali?
  • 力扣(LeetCode)22
  • 聊聊redis的数据结构的应用
  • 前端面试之闭包
  • 实战|智能家居行业移动应用性能分析
  • 使用Gradle第一次构建Java程序
  • 树莓派 - 使用须知
  • 数据仓库的几种建模方法
  • 学习Vue.js的五个小例子
  • 优化 Vue 项目编译文件大小
  • 云大使推广中的常见热门问题
  • 字符串匹配基础上
  • RDS-Mysql 物理备份恢复到本地数据库上
  • #AngularJS#$sce.trustAsResourceUrl
  • #NOIP 2014# day.1 生活大爆炸版 石头剪刀布
  • #pragma pack(1)
  • #大学#套接字
  • (4)(4.6) Triducer
  • (二)Eureka服务搭建,服务注册,服务发现
  • (免费领源码)python#django#mysql校园校园宿舍管理系统84831-计算机毕业设计项目选题推荐
  • (五) 一起学 Unix 环境高级编程 (APUE) 之 进程环境
  • (原创)攻击方式学习之(4) - 拒绝服务(DOS/DDOS/DRDOS)
  • (转)shell中括号的特殊用法 linux if多条件判断
  • (转)使用VMware vSphere标准交换机设置网络连接
  • .[hudsonL@cock.li].mkp勒索病毒数据怎么处理|数据解密恢复
  • .bat批处理(八):各种形式的变量%0、%i、%%i、var、%var%、!var!的含义和区别
  • .mat 文件的加载与创建 矩阵变图像? ∈ Matlab 使用笔记