在交互式rebase提交消息

时间:2016-01-26 14:45:28

标签: git

在git中执行交互式rebase后,我希望有一个以#(散列或磅)字符开头的提交消息,但以#开头的行被视为注释并被忽略。

有没有办法逃避#字符,使我的提交消息实际上以#开头?

更多详情

我正在使用以下方式执行交互式rebase:

git rebase -i HEAD~4

然后,在编辑器中我正在做任何需要的事情,例如:

pick b010299 #91691 Add test for logging in with valid credentials
reword 5e9159d 91691 Implement log-in feature
pick 2735aa3 #91691 Re-factor logic
pick 14bd500 #91691 Tidy up 'using' declarations

# Rebase 60d6e3f..14bd500 onto 60d6e3f
#
# 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

然后git在我的文本编辑器中为我想要重写的提交加载提交消息,但是我想在开头用#保存我的提交消息:

#91691 Implement log-in feature

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# rebase in progress; onto 60d6e3f
# You are currently editing a commit while rebasing branch 'master' on '60d6e3f'.
#
# Changes to be committed:
#   modified:   My.Website.LogInController.cs

但这意味着我的提交消息将被忽略。如何进行提交消息#91691 Implement log-in feature

1 个答案:

答案 0 :(得分:10)

如果使用#保存提交消息,则会导致提交消息为空(您还可以删除提交消息中的所有内容)。 Git会告诉你该怎么做:

Aborting commit due to empty commit message.
Could not amend commit after successfully picking 5e9159d9ce3a5c3c87a4fb7932fda4e53c7891db... 91691 Implement log-in feature
This is most likely due to an empty commit message, or the pre-commit hook
failed. If the pre-commit hook failed, you may need to resolve the issue before
you are able to reword the commit.
You can amend the commit now, with

        git commit --amend

Once you are satisfied with your changes, run

        git rebase --continue

所以,只需修改消息:

git commit --amend -m "#91691 Implement log-in feature"

继续改变:

git rebase --continue