在 Windows 上访问 git commit-msg 中的提交消息
我正在尝试编写一个 commit-msg 脚本,该脚本调用 powershell 脚本,并将提交消息作为参数传入。
到目前为止,我可以使用参数执行 powershell 脚本,但我无法弄清楚如何访问 commit-msg 内的提交消息。由于提交尚未完成,我无法使用日志。还有哪些其他选择?
这是到目前为止我在 commit-msg 中的代码:
exec c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command "& {C:/Windows/System32/WindowsPowerShell/git-pre-commit.ps1 '{the_git_commit_message}'}"
I'm trying to write a commit-msg script that calls a powershell script with the commit message passed in as a parameter.
So far I am able to execute the powershell script with parameters, but I cannot figure out how to access the commit message inside of commit-msg. Since the commit isn't completed yet, I cannot use the log. What other options are there?
Here is the code I have in commit-msg so far:
exec c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command "& {C:/Windows/System32/WindowsPowerShell/git-pre-commit.ps1 '{the_git_commit_message}'}"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
commit-msg
挂钩 ($1
) 的参数是包含该消息的文件的名称。将文件(路径)传递给powershell脚本并将您想要的内容添加到该文件中并退出脚本。另外,根据您正在执行的操作,您可能需要查看
prepare-commit-msg
挂钩PS:查看 .git/hooks 下的 commit-msg.sample 文件以获得一些想法。
The argument for the
commit-msg
hook ($1
) is the name of the file having the message. Pass the file (path) to the powershell script and add the content you want to this file and exit from the script.Also, depending on what you are doing you may want to look at
prepare-commit-msg
hookPS: Look at the commit-msg.sample file under .git/hooks to get some idea.
来自 Pro Git 书籍:
如果我理解正确,您需要实际的消息并将提交消息的内容传递给 powershell 脚本,并且对修改消息不感兴趣。
在这里阅读更多相关信息:
http://progit.org/book/ch7-3.html
干杯
From Pro Git book:
If I understand you correctly you want the actual message and pass the contents of the commit message to the powershell script and not interested in modifying the message.
Read more about it here:
http://progit.org/book/ch7-3.html
Cheers