如何“git commit”单个文件/目录

发布于 2024-12-25 16:26:08 字数 298 浏览 2 评论 0原文

我尝试了以下命令:

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

并在 Git 版本 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.

单个文件或目录提交的语法是否错误?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

岁吢 2025-01-01 16:26:08

你的论点顺序错误。尝试 git commit -m 'mynotes' path/to/my/file.ext,或者如果你想更明确, git commit -m 'mynotes' --path/到/my/file.ext。

顺便说一句,Git v1.5.2.1 已经有 4.5 岁了。您可能想要更新到较新的版本(1.7.8.3 是当前版本)。

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

爱的那么颓废 2025-01-01 16:26:08

尝试:

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

如果在当前目录,则在路径前面添加./

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

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 
机场等船 2025-01-01 16:26:08

如果您位于包含该文件的文件夹中

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

If you are in the folder which contains the file

git commit -m 'my notes' ./name_of_file.ext
瞳孔里扚悲伤 2025-01-01 16:26:08

使用 -o 选项。

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

-o, --only 仅提交指定文件

Use the -o option.

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

-o, --only commit only specified files

梦里兽 2025-01-01 16:26:08

在输入的提交消息后指定路径,例如:

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

Specify the path after the entered commit message, like:

git commit -m "commit message" path/to/file.extension
聽兲甴掵 2025-01-01 16:26:08

对于 Windows 7 上的 Git 1.9.5:“我的注释”(双引号)更正了此问题。就我而言,将文件放在 -m“消息”之前或之后没有什么区别;使用单引号是问题所在。

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.

混吃等死 2025-01-01 16:26:08

假设你正在处理一个大项目并打开了多个文件,并且你在单个文件中进行了更改,当你不需要编写 git add . 时,这会将所有文件添加到 git 中,所以您首先需要通过git status检查您在哪里进行了更改,在这里您将看到文件名旁边的所有路径,复制您进行更改的文件的路径,然后写入git add path,这里path是文件路径的整行(您修改的文件)。然后你通过 git -m "message" 编写提交消息,然后推送。

这将仅推送您与 git add file 一起使用的指定文件

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

流云如水 2025-01-01 16:26:08

如果您在 master 分支中,请尝试:

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

You try if you are in the master branch:

git commit -m "Commit message" -- filename.ext
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文