【问题标题】:How add new empty-lines in the message of one-line command "git commit -m"如何使用 -m 在 git commit 消息的单行紧凑命令中添加新的空行
【发布时间】:2022-01-21 11:20:06
【问题描述】:

如果我不想使用任何文本编辑器并将包括主题和正文行在内的所有提交消息放入有用的单行命令中:

$ git commit -m 'message including subject and body lines'

,我需要在主题之后插入第一行两行,然后在下一个新行处插入下一行。

例如:

壮举:Derezz 主控程序

  • MCP 原来是邪恶的,并一心要统治世界。
  • 此提交会将 Tron 的光盘放入 MCP。

所以我尝试使用“\n”但没有解决问题!

【问题讨论】:

    标签: git commit git-commit commit-message


    【解决方案1】:

    如果您使用 Bash(在 Linux 上或在 Windows 上使用 Git Bash),那么您可以使用 Bash 中的 $'...' 语法,它允许您使用 \n 和其他转义序列:

    $ git commit -m $'message subject\n\nmessage body'

    将创建一个带有消息的提交

    message subject
    
    message body
    

    【讨论】:

    • 太棒了!这就是我一直在寻找的解决方案。非常感谢!
    【解决方案2】:

    方法一:

    git commit -m "title" -m "A paragraph." -m "Another paragraph."
    

    方法二:

    git commit -m "title
    
    A paragraph.
    
    Another paragraph."
    

    它们的结果完全相同。请注意,在第二种方法中,您需要在每行末尾打两次 Enter(最后一行除外)。

    【讨论】:

    • 优秀的家伙!您的方法 2 是我正在寻找的另一种可能的解决方案。非常感谢!
    【解决方案3】:

    您可以多次使用-m

    git commit -m 'message including subject' -m 'and body lines'
    

    每个-m text 用一个空行分隔,所以这个命令会产生

    message including subject
    
    and body lines
    

    【讨论】:

    • 谢谢老兄。我知道,但关于你的解决方案的问题是它也在身体线之间放置了新的空线。这对我来说并不愉快。
    猜你喜欢
    • 2011-07-01
    • 2014-12-01
    • 1970-01-01
    • 2014-04-14
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    相关资源
    最近更新 更多