git Git不会添加修改过的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26049272/
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-09 02:32:37  来源:igfitidea点击:

Git won't add modified file

gitgit-add

提问by Starkers

No idea why this is happening:

不知道为什么会这样:

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)
  (commit or discard the untracked or modified content in submodules)

    modified:   file (modified content)

no changes added to commit (use "git add" and/or "git commit -a")
starkers@ubuntu:~/Documents/currentWork/protection_demo$ git add --all
starkers@ubuntu:~/Documents/currentWork/protection_demo$ 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)
  (commit or discard the untracked or modified content in submodules)

    modified:   file (modified content)

No matter what I do, git commit -am, git commit -athe file will not be added to the commit. Any help?

无论我做什么git commit -amgit commit -a该文件都不会添加到提交中。有什么帮助吗?

采纳答案by palazzo train

I think maybe Jubobs' comment is correct. Is your "file" a submodule?

我想也许 Jubobs 的评论是正确的。你的“文件”是一个子模块吗?

This line (commit or discard the untracked or modified content in submodules)should not appear for normal files.

此行(提交或丢弃子模块中未跟踪或修改的内容)不应出现在普通文件中。

Here is what I get from git status:

这是我从 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:   README.txt

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

You will not see (commit or discard the untracked or modified content in submodules)and (modified content)after my README.txt

在我的 README.txt 之后,您将不会看到(提交或丢弃子模块中未跟踪或修改的内容)(修改后的内容)

So you may need to do what git recommended, work on the content in submodules.

所以你可能需要做 git 推荐的事情,处理子模块中的内容。

Edit: Previously I thought the "git add ." could solve the issue but now I think it could not.

编辑:以前我认为“git add”。可以解决问题,但现在我认为它不能。

回答by Patrick Patterson

I had this same problem. My personal "aha" was that I had previously added a tracking .git repository file to a subfolder and thus it was seen as a submodule. After removing the .git in the subfolder, it happily joined the rest of my folders as part of just one .git file in the root folder. I didn't even know about submodules so maybe this will help someone as well.

我有同样的问题。我个人的“啊哈”是我之前在子文件夹中添加了一个跟踪 .git 存储库文件,因此它被视为子模块。删除子文件夹中的 .git 后,它很高兴地加入了我的其余文件夹,作为根文件夹中一个 .git 文件的一部分。我什至不知道子模块,所以也许这也会对某人有所帮助。

回答by Anjaneyulu Battula

You can add files in three ways

您可以通过三种方式添加文件

  • If you want to add single file use git add filenamewithpath
  • If you want to add multiple files use git add .
  • at a time you can add all files and you can write the commit message through this command

    git commit -a -m 'your commit message'

  • 如果要添加单个文件,请使用 git add filenamewithpath
  • 如果要添加多个文件,请使用 git add .
  • 一次您可以添加所有文件,并且可以通过此命令编写提交消息

    git commit -a -m 'your commit message'

回答by Apathy

Not sure if this is relevant or not, but I had the same issue when switching between Linux and Windows. I had 2 files one WEB.config and another web.config since Windows is not case sensitive it seems to have gotten confused. I renamed the file commited renamed back and commited again seems to have works.

不确定这是否相关,但是在 Linux 和 Windows 之间切换时我遇到了同样的问题。我有 2 个文件,一个是 WEB.config,另一个是 web.config,因为 Windows 不区分大小写,它似乎被混淆了。我重命名了提交的文件,重命名了,再次提交似乎有效果。

回答by GAllan

had the same problem, no idea why but a .h file would not commit.

有同样的问题,不知道为什么,但 .h 文件不会提交。

So, I renamed it, this deleted original and created new as far a git was concerned. Then I committed these changes. Git was happy.

所以,我重命名了它,这删除了原始文件并创建了新文件,就 git 而言。然后我提交了这些更改。吉特很高兴。

Then I just renamed it back. Again git was happy to commit.

然后我只是将其重新命名。git 再次乐于提交。

Cannot explain why this happened, but at least it was fixed.

无法解释为什么会发生这种情况,但至少它已修复。

回答by modle13

I had this same error:

我有同样的错误:

fatal: Cannot update paths and switch to branch 'develop' at the same time.

Then with git status:

然后git status

$ git status
warning: LF will be replaced by CRLF in .gitmodules.
The file will have its original line endings in your working directory.
On branch develop
Your branch is up-to-date with 'origin/develop'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   .gitmodules
        new file:   submodule_dir

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)
  (commit or discard the untracked or modified content in submodules)

        modified:   submodule_dir (modified content)

and git diffshowed:

git diff显示:

$ git diff
diff --git a/somedir b/somedir
--- a/somedir
+++ b/somedir
@@ -1 +1 @@
-Subproject commit some-commit-hash
+Subproject commit some-commit-hash-dirty

The issue was that I was trying to add a branch that did not yet exist in the submodule repository.

问题是我试图添加一个在子模块存储库中尚不存在的分支。

回答by Alexandr Shmidt

guys! maybe it will help someone, in my case, git didn't want to add and commit files, because I was trying to commit and add from the deeply nested folder, which doesn't contain git files. when I returned to the root folder, it added and committed easily.

伙计们!也许它会帮助某人,就我而言,git 不想添加和提交文件,因为我试图从不包含 git 文件的深层嵌套文件夹中提交和添加。当我返回根文件夹时,它很容易添加和提交。

回答by Lior Bar-On

Another option is that the same very file is in stash and is in conflict with the current copy.

另一种选择是同一个文件在 stash 中并且与当前副本冲突。

If this is the case, git stash drop- will drop the stash (with the file in conflict) and allow you to add the modified file to the index.

如果是这种情况,git stash drop- 将删除存储(文件冲突)并允许您将修改后的文件添加到索引。

回答by James Kariuki

git reset .

This did the work for me. unstaging all files that were ready for commit the (modified content) file included

这对我有用。取消暂存所有准备提交(修改内容)文件的文件

回答by Leonardo Da Vinci

It had happened with me just yesterday dude, in my case, the reason was because I was trying to call git from a subdirectory of my project. Then I used the "git add --all" and it solved the problem, also I had gone to the right directory above it also would solved de problem.

就在昨天发生在我身上,伙计,就我而言,原因是因为我试图从我的项目的子目录中调用 git。然后我使用了“ git add --all”并解决了问题,我也去了上面的正确目录,它也可以解决问题。

But what I do not get was: why in the world the git status, and git --all command was working from a subdirectory anyway? .-.

但我不明白的是:为什么在世界上 git status 和 git --all 命令无论如何都在子目录中工作?.-.

Hope it help =)

希望它有帮助 =)