简体   繁体   English

如何在git commit -a -m“ message”消息中引用分支名称?

[英]How to reference branch name in a git commit -a -m “message” message?

How to reference branch name in a message of a git commit -a -m? 如何在git commit -a -m消息中引用分支名称? Something like: 就像是:

git commit -a -m "$branchName done"

Wouter de Kort移植到bash的powershell答案是:

git commit -m "$(git rev-parse --abbrev-ref HEAD) done"

git rev-parse --abbrev-ref HEAD will give you the current branch name. git rev-parse --abbrev-ref HEAD将为您提供当前的分支名称。 You do have to make sure that there is at least one commit in the branch otherwise this won't work. 您必须确保分支中至少有一个提交,否则将无法正常工作。 Depending on your OS/shell you can then use some string concatenation to create your commit message. 然后,根据您的OS / shell,可以使用一些字符串连接来创建提交消息。

This is a PowerShell sample: 这是一个PowerShell示例:

$branchName = git rev-parse --abbrev-ref HEAD
git commit -m "Initial commit on branch $branchName"

方式之一:

git commit -am "$(git branch | awk '/\*/ { print $2; }') done"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM