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

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

问题描述

我做了一个 git commit -mmessage像这样:

 > git commit -msave arezzo files
#在分支主机上
#没有为commit提交的更改:
#(使用git add< file> ...来更新提交)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#修改:arezzo.txt
#修改:arezzo.jsp

没有更改添加到提交(使用git add和/或git commit -a)

但是之后,当我做 git status 时,它显示了相同的修改过的文件:

 > git status 
#在分支主机上
#不会为commit提交更改:
#(使用git add< file> ...更新将提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#修改:arezzo.txt
#修改:arezzo.jsp
$
没有更改添加到提交中(使用git add和/或git commit -a)

我做错了什么?

解决方案

b


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

Git有一个临时区域,在提交之前需要添加文件,您可以在这里阅读它的解释



对于你的具体例子,你可以使用:

  git commit -am保存arezzo文件

(注意在标志中额外的 a ,也可以写成 git commit -a -mmessage - 都做同样的事情)



另外,如果你想更有选择性添加到提交中的内容,您可以使用 git add 命令将相应的文件添加到暂存区域和 git status 来预览即将添加的内容(请注意注意 b
$ b

你也可以在 git文档页面 ,它将提供有关分段/添加文件概念的更多详细信息。





另外一件值得了解的事情是 互动式分段 - 这允许您将文件的部分添加到暂存区域,所以如果您对三个不同的代码更改(相关但不同的功能)进行了更改,则可以使用交互模式分割更改并添加/依次提交每个部分。具有较小的特定提交可能会有所帮助。


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

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

What am I doing wrong?

解决方案

As the message says:

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

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"

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

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

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天全站免登陆