首页 文章

如何使用命令行中的“message”和“description”进行更改? [重复]

提问于
浏览
262

这个问题在这里已有答案:

我是 git 和GitHub的新手 . 我设法在我的Mac上本地设置所有内容,所以现在我可以通过 git (在命令行上而不是Mac应用程序)将提交推送到GitHub .

当我直接从GitHub Web界面推送提交时(例如快速修复拼写错误),我有机会"comment"提交,GitHub给我一个提交 Headers 和提交描述 . 我发现这非常有用 .

仍然,当我从本地机器 git push 时, git 打开我的默认编辑器:所以我写了提交注释,然后GitHub自动将它分为title和"body" . 有没有办法从终端评论提交?

4 回答

  • 40

    还有另一种直接且更清晰的方式

    git commit -m "Title" -m "Description ..........";
    
  • 0

    使用不带任何标志的 git commit 命令 . 配置的编辑器将打开(在本例中为Vim):

    enter image description here

    要开始键入,请按键盘上的INSERT键,然后在插入模式下创建一个更好的提交,其中包含您想要的描述 . 例如:

    enter image description here

    一旦你编写了你需要的所有内容,返回到git,首先应该退出插入模式,然后按ESC键 . 现在通过在键盘上键入 :wq (w - write,q - quit)来关闭Vim编辑器并保存更改:

    enter image description here

    然后按ENTER键 .

    在GitHub上,这个提交将如下所示:

    enter image description here

    作为提交编辑器,您可以使用VS Code

    git config --global core.editor "code --wait"
    

    来自VS Code docs网站: VS Code as Git editor

    Gif演示:
    enter image description here

  • 207
    git commit -a -m "Your commit message here"
    

    将使用提交消息快速提交所有更改 . Git提交“title”和“description”(正如你所说的)只不过是第一行,而提交消息中的其余行通常按空格分隔 . 所以使用这个命令只会提交“ Headers ”而没有描述 .

    如果您想提交更长的消息,可以这样做,but it depends on which shell you use .

    在bash中,快速的方法是:

    git commit -a -m $'Commit title\n\nRest of commit message...'
    
  • 528

    如果您想在创建提交后使用 Headers 和正文改进提交消息,则可以reword它 . 这种方法更有用,因为您只有在编写代码后才能知道代码的作用 .

    git rebase -i origin/master
    

    然后,您的提交将出现:

    pick e152ce2 Update framework
    pick ffcf91e Some magic
    pick fa672e1 Update comments
    

    选择要重新设置并保存的提交 .

    pick e152ce2 Update framework
    reword ffcf91e Some magic
    pick fa672e1 Update comments
    

    现在,您有机会添加 Headers 和正文,其中第一行将是 Headers .

    Create perpetuum mobile
    
    Redesign laws of physics with a pinch of imagination. Open a wormhole in 23 dimensions. Add protection to avoid high instability.
    

相关问题