Git:提交并自动添加所有未跟踪文件 [英] Git: commit and automatically add all untracked files
问题描述
我经常忘记我有一些新文件,并直接做,
I often forgot that I have some new files and directly do,
git commit -a -m "My commit message"
这只会提交已更改的文件,而我必须在新的提交中添加剩余的文件。这意味着有两个单独的提交,尽管在逻辑上它们是同一任务的一部分。
This only commits changed files, and I have to do add the remaining files in a new commit. This means that there are two separate commits although logically they are part of the same task.
我知道通过两个连续命令在提交中包含未跟踪文件的最简单方法:
The easiest way I know to include untracked files in the commit via two consecutive commands:
git add -A
git commit -a -m "My commit message"
是否可以在一个命令中使用与上面相同的效果?
Is it possible to have the same effect like the above in one command?
推荐答案
在您的执行路径中创建一个名为(无扩展名)的文件: git-add-commit-untracked
Create a file in your execution path called (no extension): git-add-commit-untracked
把它放在里面:
Put this in it:
#!/bin/bash
message=${0}
git add -A
git commit -am "$message"
然后:
git-add-commit-untracked提交消息
您可以使用较短的文件名称。为了便于说明,我将其留下了很长时间。
You can use a shorter name for the file though. I left it lengthy for illustrative purposes.
这篇关于Git:提交并自动添加所有未跟踪文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!