Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git add and commit single tracked file in one command

Tags:

I'm looking for the equivalent of git commit -am "blah blah" but for just a single file. If I try:

git commit my.file -am "blah blah"

I get:

fatal: Paths with -a does not make sense.

I looked around but I could only find solutions that suggest using aliases (e.g. this one), but even those don't seem like they could be modified because I need to pass an argument. Do I have to resort to calling git through a shell?

It seems like there should be a simpler option for something that I imagine would be extremely common. Right now I'm stuck with:

git add my.file
git commit -m "blah blah"
like image 337
BrodieG Avatar asked Oct 16 '14 14:10

BrodieG


1 Answers

Just omit the -a which means --all which is not what you want. Do this:

git commit my.file -m "blah blah"

That will commit only my.file, even if other files are staged (by git add).

like image 94
John Zwinck Avatar answered Dec 12 '22 07:12

John Zwinck