Git列出了相同的文件修改,并没有提交进行提交? [英] Git lists same file modified and not staged for commit?

查看:323
本文介绍了Git列出了相同的文件修改,并没有提交进行提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,Git告诉我我有一个既承诺又未提交的文件?这是没有道理的:

 %git status 
#分支主
#更改为提交:
#(使用git reset HEAD< file> ...停用)

#修改:Dir1 / Dir2 / filename.cpp

#没有为commit提交更改:
#(使用git add< file> ...更新将提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#modified:Dir1 / Dir2 / filename.cpp

Dir1 Dir2 filename.cpp 绝对是同一个文件。我必须再次添加 filename.cpp 以使其显示为要提交的更改(最初位于存储库之后)。关于可能导致问题的唯一原因是我隐藏了 pull --rebase ,然后弹出隐藏 .gitignore 不会列出 Dir1 Dir2 filename.cpp 任何地方,这些模式并不表明他们会捕获这个文件?

解决方案

它意味着你对 filename.cpp 进行了修改,添加了这个修改(使用 git add ),然后进行了另一项尚未添加的更改。



要提交的更改部分意味着Git更新了索引并进行了更改。当你运行 git commit 时,对索引的更改将被用来创建新的提交对象。



更改不上演部分显示了索引与工作副本之间的差异。



您可以重现您看到的内容:


  • 编辑文件名.cpp

  • 运行 git status 。您将看到更改未暂存。

  • 运行 git add filename.cpp

  • 运行 git status 。您将看到要更改的提交。

  • 再次编辑filename.cpp

  • 运行 git status 。您将看到更改未暂存和要更新提交。



这是否合理?解释Git如何工作总是有点棘手。


For some reason Git is telling me I have a file which is both "to be committed" and also "not staged for commit"? This doesn't make sense:

% git status 
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   Dir1/Dir2/filename.cpp
#
# 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:   Dir1/Dir2/filename.cpp

Dir1, Dir2 and filename.cpp are definitely all the same file. I had to add filename.cpp back again to get it to appear as a change to be committed (after it was originally in the repository). About the only thing that may have caused the problem was that I stashed, pull --rebase, then popped the stash? .gitignore does not list Dir1, Dir2 or filename.cpp anywhere and the patterns don't suggest they would catch this file?

解决方案

It means that you made a change to filename.cpp, added that change (with git add), then made another change that has not yet been added.

The "changes to be committed" part means that Git has updated its index with a change. When you run git commit, the changes to the index will be used to create the new commit object.

The "changes not staged" part shows the difference between the index and your working copy.

You can reproduce what you're seeing like so:

  • Edit filename.cpp
  • Run git status. You'll see "changes not staged".
  • Run git add filename.cpp
  • Run git status. You'll see "changes to be committed".
  • Edit filename.cpp again
  • Run git status. You'll see both "changes not staged" and "changes to be committed".

Does that make sense? It's always a little tricky explaining how Git works.

这篇关于Git列出了相同的文件修改,并没有提交进行提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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