我做了一个 git commit -m "message"
像这样:
> git commit -m "save arezzo files"
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: arezzo.txt
# modified: arezzo.jsp
#
no changes added to commit (use "git add" and/or "git commit -a")
但之后,当我执行 git status
时,它会显示相同的修改文件:
> git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: arezzo.txt
# modified: arezzo.jsp
#
no changes added to commit (use "git add" and/or "git commit -a")
我做错了什么?
最佳答案
正如消息所说:
no changes added to commit (use "git add" and/or "git commit -a")
Git 有一个“暂存区”,文件在提交前需要添加到这里,你可以 read an explanation of it here .
对于您的具体示例,您可以使用:
git commit -am "save arezzo files"
(注意标志中额外的 a
,也可以写成 git commit -a -m "message"
- 两者做同样的事情)
或者,如果您想对添加到提交中的内容更有选择性,可以使用 git add 命令将适当的文件添加到暂存区,以及 git status 预览即将添加的内容(记住要注意使用的措辞)。
您还可以在 git documentation page 上找到有关如何使用 git 的一般文档和教程。 这将提供有关暂存/添加文件概念的更多详细信息。
另一件值得了解的事情是 interactive staging - 这允许您将文件的部分 添加到暂存区,因此如果您进行了三个不同的代码更改(针对相关但不同的功能),您可以使用交互模式来拆分更改并依次添加/提交每个部分。像这样进行较小的特定提交会很有帮助。
关于git - 为什么 'git commit' 不保存我的更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7704480/