27

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" 

1 Answer 1

44

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).

Sign up to request clarification or add additional context in comments.

3 Comments

Jeez, can't believe it was that simple. I didn't realize I could commit without staging (the "Changes not staged for commit:" message threw me off). No wonder no one else asked this question... I also missinterpreted the -a to mean add.
This will commit the file even though it's not yet staged by git add. (I didn't believe that at first -- though it's mentioned both in question and in the above comment(!), so explicitly mentioning it here.)
However, if a file is yet untracked, this won't commit it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.