如何改写了第一个git的承诺消息?(How do I reword the very first g

2019-06-27 02:52发布

我有一个包含3个commmits工作树:

➜〜myproject的GIT中:(主) 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)

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

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

(...进入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

在这种情况下,我想纠正( reword在git的说法)有问题的提交信息:

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

...适当的东西。

不出所料,我上面的尝试没有成功,因为第一承诺显然不具有任何提交。 (当你rebase ,你需要参考未来之前 ,您希望将一个最古老的承诺reword了吧?)

我的问题的要点,因此,可以通过你做的任何其他手段实现这一目标?

Answer 1:

不要git rebase -i --root

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

这样,根提交也包括在内,你可以直接reword它像任何其他承诺。

--root选项在Git的引进v1.7.12 (2012)。 在此之前唯一的选择是使用filter-branchamend ,这通常是更难做。

注:也看到这个类似的问题和答案 。



Answer 2:

您可以随时使用git filter-branch --msg-filter

git filter-branch --msg-filter \
  'test $GIT_COMMIT = '$(git rev-list --reverse master |head -n1)' &&
echo "Nice message" || cat' master


Answer 3:

pcreux的要点有改写的第一次提交的好方法:

# You can't use rebase -i here since it takes the parent commit as argument.
# You can do the following though:
git checkout FIRST_COMMIT_SHA && git commit --amend && git rebase HEAD master


文章来源: How do I reword the very first git commit message?