如何编辑git中任何提交的提交消息? [英] How do I edit the commit message of any commit in git?

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

问题描述

假设我有3个未完成的提交。现在我想更改第一次或第二次提交的提交消息(使用 git commit --amend )更改第三次提交的提交消息很简单。如何做到这一点?

解决方案

为了反弹子问题:是否有一个 git commit - 对于之前的提交(而不仅仅是最后一个提交),你可以尝试类似的东西(尚未测试,但 Colin O'Dell colinodell / git-amend-old ):

  git checkout -b tmp 
git reset --hard HEAD〜2
git commit --amend
git rebase --onto tmp HEAD @ {1} master
$ b $ p



$ $ p $ x --- x- --x --- x --- x
^
|
(master *)(* =当前分支)

git checkout -b tmp
x --- x --- x --- x --- x
^
|
(tmp *,master)

git reset --hard HEAD〜2
x --- x --- x --- x --- x
^ ^
| |
(tmp *)(master)

git commit -amend
y(tmp *)
/
x --- x --- x- --x --- x
| ^
(HEAD @ {1})|
(master)

git rebase --onto tmp HEAD @ {1} master
(tmp)
--- --- x'--- x'( master *)
/
x --- x --- x --- x --- x(仅在reflog中引用)


Let's say I have 3 unpushed commits. Now I want to change the commit message of the first or second commit (changing them for the third one is simple using git commit --amend). How to do that?

解决方案

To rebound on the sub-question: is there a git commit --amend for a previous commit (and not just the last one), you could try something like (not tested yet, but Colin O'Dell mentions in the comments having written a script for it colinodell/git-amend-old):

git checkout -b tmp
git reset --hard HEAD~2
git commit -amend 
git rebase --onto tmp HEAD@{1} master

That would be like:

x---x---x---x---x
                ^
                |
               (master*) (* = current branch)

git checkout -b tmp
x---x---x---x---x
                ^
                |
               (tmp*, master) 

git reset --hard HEAD~2
x---x---x---x---x
        ^       ^
        |       |
      (tmp*) (master) 

git commit -amend 
      y (tmp*) 
     /
x---x---x---x---x
        |       ^
   (HEAD@{1})   |
          (master) 

git rebase --onto tmp HEAD@{1} master
    (tmp)
      y---x'---x' (master*) 
     /
x---x---x---x---x (only referenced in reflog)

这篇关于如何编辑git中任何提交的提交消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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