Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

How to 'git commit' a single file/directory

Writer Matthew Martinez

I tried the following command:

git commit path/to/my/file.ext -m 'my notes'

And received an error in Git version 1.5.2.1:

error: pathspec '-m' did not match any file(s) known to git.
error: pathspec 'MY MESSAGE' did not match any file(s) known to git.

Is that incorrect syntax for a single file or directory commits?

3

8 Answers

Your arguments are in the wrong order. Try git commit -m 'my notes' path/to/my/file.ext, or if you want to be more explicit, git commit -m 'my notes' -- path/to/my/file.ext.

Incidentally, Git v1.5.2.1 is 4.5 years old. You may want to update to a newer version (1.7.8.3 is the current release).

11

Try:

git commit -m 'my notes' path/to/my/file.ext 

of if you are in the current directory, add ./ to the front of the path;

git commit -m 'my notes' ./path/to/my/file.ext 
1

If you are in the folder which contains the file

git commit -m 'my notes' ./name_of_file.ext
2

Use the -o option.

git commit -o path/to/myfile -m "the message"

-o, --only commit only specified files

2

Specify the path after the entered commit message, like:

git commit -m "commit message" path/to/file.extension

For Git 1.9.5 on Windows 7: "my Notes" (double quotes) corrected this issue. In my case, putting the file(s) before or after the -m 'message' made no difference; using single quotes was the problem.

Suppose you are working on big project and have opened multiple files, and you made changes in single file, when you don't need to write git add ., this will add all the files to git, so you first need to check where you made changes by git status, here you will see all the paths next to the filenames, copy the path of the file where you made change and then write git add path, here path is whole line of path to the file (your modified file). Then you write your commit message by git -m "message" and then push.

This will push only the specified file which you have used with git add file

You try if you are in the master branch:

git commit -m "Commit message" -- filename.ext
0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy