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?
Untracked basically means that Git sees a file you didn't have in the previous snapshot (commit), and which hasn't yet been staged; Git won't start including it in your commit snapshots until you explicitly tell it to do so.
In order to stash untracked files, add the “–include-untracked” option to your “git stash” initial command. Alternatively, you can simply use the “-u” which is equivalent to the untracked longer version.
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"
Then: git-add-commit-untracked "Commit message"
You can use a shorter name for the file though. I left it lengthy for illustrative purposes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With