为什么“git commit"不保存我的更改? [英] Why does 'git commit' not save my changes?

查看:47
本文介绍了为什么“git commit"不保存我的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个 git commit -m "message" 像这样:

I did a git commit -m "message" like this:

> 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 时,它显示了相同的修改后的文件:

But afterwards, when I do git status it shows the same modified files:

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

我做错了什么?

推荐答案

正如消息所说:

未向提交添加任何更改(使用git add"和/或git commit -a")

no changes added to commit (use "git add" and/or "git commit -a")

Git 有一个暂存区",需要在提交前添加文件,你可以 在此处阅读对它的解释.

Git has a "staging area" where files need to be added before being committed, you can read an explanation of it here.


对于您的具体示例,您可以使用:


For your specific example, you can use:

git commit -am "save arezzo files"

(注意标志中额外的 a,也可以写成 git commit -a -m "message" - 两者都做同样的事情)

(note the extra a in the flags, can also be written as git commit -a -m "message" - both do the same thing)

或者,如果您想对添加到提交中的内容更具选择性,您可以使用 git add 命令将适当的文件添加到暂存区,并且 git status 到预览即将添加的内容(记得注意用词).

Alternatively, if you want to be more selective about what you add to the commit, you use the git add command to add the appropriate files to the staging area, and git status to preview what is about to be added (remembering to pay attention to the wording used).

您还可以在 git 文档页面上找到有关如何使用 git 的一般文档和教程这将提供有关暂存/添加文件概念的更多详细信息.

You can also find general documentation and tutorials for how to use git on the git documentation page which will give more detail about the concept of staging/adding files.


另一件值得了解的事情是交互式登台- 这允许您将文件的一部分添加到暂存区,因此如果您进行了三个不同的代码更改(针对相关但不同的功能),您可以使用交互模式来拆分更改并依次添加/提交每个部分.像这样进行较小的特定提交可能会有所帮助.


One other thing worth knowing about is interactive staging - this allows you to add parts of a file to the staging area, so if you've made three distinct code changes (for related but different functionality), you can use interactive mode to split the changes and add/commit each part in turn. Having smaller specific commits like this can be helpful.

这篇关于为什么“git commit"不保存我的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆