You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git如何复用完整提交信息(主题+描述)?现有命令仅获主题求解决

Fixing Git Commit: Reusing Full Commit Messages (Subject + Body)

Ah, I’ve run into this exact frustration before! When you use git commit --reuse-message or --reedit-message, it’s supposed to pull in the full commit message, but sometimes Git’s default behavior or edge cases can make it only grab the subject line. Let’s go through the reliable fixes that will get you the complete message every time:

Method 1: Directly Import the Full Message with git show

This is the most foolproof way to pull in the entire commit message (subject + body):

  • Run this command to reuse the message without editing:

    git commit -F <(git show --format=%B YOUR_COMMIT_ID_OR_REF)
    

    The --format=%B flag tells Git to output the full, unmodified commit message (including all line breaks and body text). The <(...) syntax is a process substitution that passes the output directly to git commit -F (which reads the message from a "file").

  • If you want to edit the message before committing, add the --edit flag:

    git commit --edit -F <(git show --format=%B YOUR_COMMIT_ID_OR_REF)
    

    This will open your default editor with the full commit message ready for tweaks.

For Windows Users (Command Prompt/PowerShell)

Process substitution doesn’t work natively in Windows shells, so use a temporary file instead:

  1. Export the full commit message to a file:
    git show --format=%B YOUR_COMMIT_ID_OR_REF > commit-message.txt
    
  2. Use the file to commit (with or without editing):
    # No edit
    git commit -F commit-message.txt
    
    # With edit
    git commit --edit -F commit-message.txt
    
  3. Clean up the temporary file when done:
    del commit-message.txt
    

Why Your Original Commands Might Have Failed

In most cases, --reuse-message should work for full messages, but here are a few reasons it might not:

  • Commit message formatting: If your original commit message uses unusual line breaks or comment characters (starting with #), Git might truncate parts of it when using the reuse flags.
  • Git version quirks: Older Git versions (pre-2.20) had occasional bugs with message reuse for certain commit types (like merge commits). Updating Git can fix this, but the git show method works across all versions.
  • Refspec issues: If you’re using a ref like HEAD~1 but the commit is a merge, Git might pull the merge message instead of the full feature commit message. Using the explicit commit ID avoids this ambiguity.

Bonus: Create an Alias for Ease

If you do this often, add an alias to your Git config to save typing:

git config --global alias.reuse-commit '!f() { git commit -F <(git show --format=%B "$1"); }; f'

Now you can just run:

git reuse-commit YOUR_COMMIT_ID_OR_REF

内容的提问来源于stack exchange,提问作者Marek Bocian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:15:27