博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Changing Your Commit Messages
阅读量:5883 次
发布时间:2019-06-19

本文共 2723 字,大约阅读时间需要 9 分钟。

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 updatespick 36c7dba updated ticgit gempick 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 updatespick 36c7dba updated ticgit gemedit 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~3Stopped at 7482e0d... updated the gemspec to hopefully work betterYou can amend the commit now, with	git commit --amendOnce 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/ucliaohh/blog/730114

你可能感兴趣的文章
JavaScript高级程序设计--对象,数组(栈方法,队列方法,重排序方法,迭代方法)...
查看>>
【转】 学习ios(必看经典)牛人40天精通iOS开发的学习方法【2015.12.2
查看>>
在 ASP.NET MVC 中使用异步控制器
查看>>
SQL语句的执行过程
查看>>
详解Linux中Load average负载
查看>>
HTTP 协议 Cache-Control 头——性能啊~~~
查看>>
PHP遍历文件夹及子文件夹所有文件
查看>>
WinForm程序中两份mdf文件问题的解决
查看>>
程序计数器、反汇编工具
查看>>
Android N: jack server failed
查看>>
如何将lotus 通讯簿导入到outlook 2003中
查看>>
WinForm 应用程序中开启新的进程及控制
查看>>
js replace,正则截取字符串内容
查看>>
Thinkphp5笔记三:创建基类
查看>>
查询反模式 - GroupBy、HAVING的理解
查看>>
Android中EditText,Button等控件的设置
查看>>
TextKit简单示例
查看>>
网格最短路径算法(Dijkstra & Fast Marching)(转)
查看>>
软链接和硬链接详解
查看>>
Redis_master-slave模式
查看>>