Commit changes only in one directory in Git
Why does no one mention you can simply
git commit -m 'message' -- my-dir
It seems to me the OP isn't used to / doesn't like to use the staging area directly. This approach is also a lot safer to recommend without further context, because chances are that a defaault commit (of everything that's staged) will
- commit more than just my-dir if it already had been staged
- will produce confusing results when the OP is not used to managing the staging area explicitly (because the working tree can have gotten out of synch with the index)
Omit the -a
option. Then git
will commit only the files that you staged with git add
.
You can also try committing the directory without staging with git commit my-dir
.