【发布时间】:2016-05-03 04:15:30
【问题描述】:
在 git 中执行交互式变基后,我想要一个以 #(哈希或井号)字符开头的提交消息,但以 # 开头的行被视为 cmets 并被忽略。
有什么方法可以转义# 字符,使我的提交消息实际上以# 开头?
更多详情
我正在使用以下方式执行交互式变基:
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?
【问题讨论】:
-
它并不漂亮,但它比公认的答案更快:在“#”前面添加一个空格。因为只有以字符开始的行被忽略。
-
只有在它有效时才会更快 ;-) 我一开始就想要哈希的原因是因为我的问题跟踪集成正在寻找以哈希开头的提交。我想这是可能如果有前导空格它会找到它们,但文档表明它需要以哈希开头。
标签: git