Git:文件“已更改但未更新”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4812096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:59:15  来源:igfitidea点击:

Git: file "changed but not updated"

git

提问by Nate Reed

What does "Changed but not updated mean"? These files are in git, they've been modified but when I run "git status," these changes appear under "Changed but not updated" instead of "Changes to be commited."

“已更改但未更新”是什么意思?这些文件在 git 中,它们已被修改,但是当我运行“git status”时,这些更改出现在“已更改但未更新”下,而不是“要提交的更改”下。

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# modified:   breakouts/views.py
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified:   templates/registration/login.html
# modified:   templates/registration/registration.html

# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
# context_processors.py
# static/#css.css#

Since they've already been added why aren't they "Changes to committed"?

既然它们已经被添加,为什么它们不是“已提交的更改”?

回答by KitsuneYMG

You have to use git addevery time ORuse git commit -aor git commit --allinstead of plain git commit.

您必须git add每次都使用OR使用git commit -aorgit commit --all代替普通git commit.

from Git docs:

来自Git 文档

-a
--all
  Tell the command to automatically stage files that have been modified
  and deleted, but new files you have not told git about are not affected.

addis basically the "take notice of this file/directory" command. Not CVS's or subversion's track changes to this file.

add基本上是“注意这个文件/目录”命令。不是 CVS 或 subversion 对这个文件的跟踪更改。

回答by Simon

Every time you modify a file, you have to add it using git addto be able to commit it, even if you did add it at the beginning.

每次修改文件时,您都必须使用添加它git add才能提交它,即使您在开始时添加了它。

回答by ocodo

The git add <file>adds the 'changes' to your local commit schedule, if those changes aren't added, then they aren't committed.

git add <file>增加了“变化”到本地提交的时间表,如果不添加这些变化,那么他们都不敢承诺。

Why? This is git's workflow, just like anything there is terminology that is open to interpretation, perhaps you're used to SVN's idea of add, try to forego what you assume and learn how git does things.

为什么?这是 git 的工作流程,就像任何有可以解释的术语一样,也许您已经习惯了 SVN 的想法add,尝试放弃您的假设并学习 git 如何做事。