首页 > 解决方案 > 将修改文件列表放入 git commit 消息中

问题描述

我正在尝试向我添加一个别名.gitconfig,它将自动将当前存储库中的所有修改文件添加到提交消息中。

我尝试处理git status --porcelainusingcut和的输出awk

我开始awk工作了,但我确信有更好的解决方案可以产生更好的提交消息。

# in my .gitconfig
g = !git commit --all --message "edited:$(git status --porcelain | awk '{printf \"%s%s\",(NR>1?\",\":\"\"),$2} END{print \"\"}')"
# on the command-line
git commit --all --message "edited:$(git status --porcelain | awk '{printf \"%s%s\",(NR>1?\",\":\"\"),$2} END{print \"\"}')"

git log,我看到提交消息,如edited:dir1/file1,dir2/file2.

我想清理代码和/或改进提交消息。

标签: bashgitshellunixversion-control

解决方案


该信息已经在您的提交中可用。你只需要跑git log --stat去看它。

我经常使用它,以至于我在我的.gitconfig

[alias]
    ls = log --stat

所以每当我使用时,git ls我都会得到统计输出。


推荐阅读