git:提交多个文件但添加消息 [英] git: Commit multiple files but add messages
问题描述
我的回购协议中有大量文件,有时我会处理20个文件,而且我想提交所有这些文件。但是,我想为每个添加一条消息。
如何添加已更新的所有这些文件,并为每个文件添加消息而无需运行手动为每一个命令?这是可能做一个批量运行,并提示我为每一个添加消息?
我会推荐做每个人的承诺。但是,您可以通过使用小型shell脚本自动执行此过程。
例如:
#!/ bin / sh
PROJECT_DIR =。
用于$ {PROJECT_DIR}中的FILE / *
git add $ {FILE}
git commit
完成
在当前表单中,脚本将当前工作目录视为 PROJECT_DIR
。然后遍历所有文件(匹配* glob),添加并将它们单独提交到存储库。 git会跳过未更改的文件,并且编辑器将启动每个更改的文件以提示您提交提交消息。
如果系统提示您对不想提交的文件发表评论,只需保存提交消息文件,不做任何更改,git将跳过它。 / p>
I have tons of files in my repo, and sometimes I work on 20 files and I want to commit all of them. But, I would like to add a message for each.
How can I add all of these files that have been updated and also add a message for each without having do run a command for each one manually? Is this possible to do a bulk run and have it prompt me to add a message for each one?
I would recommend doing a commit for each one. However, you can automate the process by using a small shell script.
For example:
#!/bin/sh
PROJECT_DIR=.
for FILE in ${PROJECT_DIR}/*
do
git add ${FILE}
git commit
done
In it's current form, the script considers the current working directory the PROJECT_DIR
. It then iterates through all files (that match the * glob), adding and commiting them individually to the repository. Unchanged files are skipped by git and for each changed file your editor will fire up to prompt you for a commit message.
If you're prompted to comment on a file you do not want to commit yet, just save the commit message file without any changes and git will skip over it.
这篇关于git:提交多个文件但添加消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!