Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to 'git commit' a single file/directory

Tags:

git

commit

People also ask

Can we commit single file in git?

1 Answer. Then you can git commit a single file directory.

How do I commit a directory in git?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.

How do you add an individual file for a commit?

Save the file or files. Add only one file, or one part of the changed file: git add README.md. Commit the first set of changes: git commit -m "update the README to include links to contributing guide" Add another file, or another part of the changed file: git add CONTRIBUTING.md.


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


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 

If you are in the folder which contains the file

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

Use the -o option.

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

-o, --only commit only specified files


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.