我如何改写第一个git commit消息? [英] How do I reword the very first git commit message?

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

问题描述

我有一个包含3个通讯的工作树:



➜〜myproject git:(master) git log

 提交a99cce8240495de29254b5df8745e41815db5a75 
作者:我的名字< my@mail.com>
日期:8月16日星期四00:59:05 2012 +0200

.gitignore编辑

提交5bccda674c7ca51e849741290530a0d48efd69e8
作者:我的名字< my @ mail.com>
日期:星期一8月13日01:36:39 2012 +0200

创建.gitignore文件

提交6707a66191c84ec6fbf148f8f1c3e8ac83453ae3
作者:我的名字< my @ mail.com>
日期:星期一8月13日01:13:05 2012 +0200

初始提交(带有误导性消息)



现在我想 reword 我的第一次提交的提交消息(6707a66)



➜〜myproject git :(主) git rebase -i 6707



(...进入vim)

 选择5bccda6创建.gitignore文件
选择a99cce8 .gitignore编辑

#将6707a66..a99cce8编辑到6707a66

#命令:
#p,pick =使用提交
#r,reword =使用提交,但编辑提交消息
#e,edit =使用提交,但停止修改
#s,squash =使用commit,但融入前面的提交
#f,fixup = likesquash,但放弃这个提交的日志消息
#x,exec = run命令其余部分)使用shell

#这些行可以重新排序;他们从上到下执行。

#如果你在这里删除一行,那么COMMIT将会丢失。
#但是,如果您删除了所有内容,rebase将会中止。

#注意空提交被注释掉

在这种情况下,我希望纠正( reword 用git的说法)提交的消息:


初始提交(带有误导性消息)


...适当的设置。

<不出所料,我的上面的尝试没有成功,因为第一次提交显然没有任何提交。 (当你 rebase 时,你需要引用下一个最旧的提交之前到你想要的 reword code>,对吧?)



我的问题的要点可以通过其他方式实现吗?

解决方案 $ g
$ $ b

(指向 root ,而不是指向特定的提交)



这样,根commit也包含在内,你可以像 reword 那样执行任何其他提交。

其他更精细的方法存在,但其中大多数在2012年前的'v1.7.12'中添加了'--root'选项。


I have a working tree containing 3 commmits:

➜ ~myproject git:(master) git log

commit a99cce8240495de29254b5df8745e41815db5a75
Author: My Name <my@mail.com>
Date:   Thu Aug 16 00:59:05 2012 +0200

    .gitignore edits

commit 5bccda674c7ca51e849741290530a0d48efd69e8
Author: My Name <my@mail.com>
Date:   Mon Aug 13 01:36:39 2012 +0200

    Create .gitignore file

commit 6707a66191c84ec6fbf148f8f1c3e8ac83453ae3
Author: My Name <my@mail.com>
Date:   Mon Aug 13 01:13:05 2012 +0200

    Initial commit (with a misleading message)

Now I wish to reword the commit message of my first commit (6707a66)

➜ ~myproject git:(master) git rebase -i 6707

(…entering vim)

pick 5bccda6 Create .gitignore file
pick a99cce8 .gitignore edits

# Rebase 6707a66..a99cce8 onto 6707a66
#
# 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
#
# 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

In this case, I wish to correct (reword in git parlance) the commit message in question:

Initial commit (with a misleading message)

…to something appropriate.

Unsurprisingly, my attempt above didn't succeed since the first commit obviously doesn't have any parent commit. (And when you rebase, you need to reference the next oldest commit prior to the one you wish to reword, right?)

The gist of my question, thus, can you achieve this by any other means of doing it?

解决方案

Do git rebase -i --root

(point to root instead of pointing to a specific commit)

This way, the root commit is also included and you can just reword it like any other commit.

Other, more elaborate approaches exist, but most of these pre-date the addition of the '--root' option in 'v1.7.12', from 2012.

这篇关于我如何改写第一个git commit消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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