如何编辑/修改Git中最后一个提交之前的提交消息? [英] How to edit/amend commit messages for commits previous to the last in Git?

查看:291
本文介绍了如何编辑/修改Git中最后一个提交之前的提交消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如在SO ,当我需要编辑/更正上次提交的消息时,我会这样做:

  git commit --amend -m新的提交信息

但是当我想修改提交信息时,我该怎么做对于最后一个之前的提交?例如,第14次最后一次提交 - 还考虑到提交没有被推送到远程?



有没有办法在不重置以前的提交的情况下执行此操作?在这种情况下, rebase 是否是正确的做法? 你需要这里提到的交互式rebasing:如何修改git中的指定提交?



不同之处在于,您不需要 edit ,只需要 reword 提交问题,因为您只是想编辑提交消息。



这是另一个有用的资源: https://help.github.com/articles/interactive-rebase



edit: reword 只适用于版本1.6.6或更新版本,如OP所述。

As shown on this popular answer in SO, when I need to edit/correct the message for the last commit, I do:

git commit --amend -m "New commit message"

But what am I supposed to do when I want to amend commit messages for commits previous to the last one? For instance, the 14th last commit - also considering that commits have not been pushed to remote?

Is there a way of doing this without resetting previous commits? Would rebase be the right thing to do in this case?

解决方案

You would need interactive rebasing as mentioned here: How to modify a specified commit in git?

The difference being, instead of edit you'll just want to reword the commit in question since you just want to edit the commit message.

Here's another useful resource: https://help.github.com/articles/interactive-rebase

edit: reword only works on versions 1.6.6 or newer as noted by the OP.

这篇关于如何编辑/修改Git中最后一个提交之前的提交消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆