Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git commit在索引中保留更改 问题_Git - Fatal编程技术网

git commit在索引中保留更改 问题

git commit在索引中保留更改 问题,git,Git,我正试图提交一些更改,但它们被甩在后面了 我不明白的原因: 我看一看当前的回购状态: % git status On branch new-master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: __init__.py new file: api/__init__.py new file: api/api.py new

我正试图提交一些更改,但它们被甩在后面了 我不明白的原因:

我看一看当前的回购状态:

% git status
On branch new-master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   __init__.py
    new file:   api/__init__.py
    new file:   api/api.py
    new file:   api/common.py
    new file:   api/error.py

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:   ../status/server.py
    modified:   __init__.py

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    ../env/
    ../foo.db
并立即重新运行状态,以确保没有任何更改:

% git status
On branch new-master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   __init__.py
    new file:   api/__init__.py
    new file:   api/api.py
    new file:   api/common.py
    new file:   api/error.py

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:   ../status/server.py
    modified:   __init__.py

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    ../env/
    ../foo.db
那是刚刚设置好的。现在是真正的乐趣。我对你的行为很反感
——添加
的意图(我可能不明白它是做什么的),但这会复制 我的全部问题是:

mkdir subdir && mkdir subdir/another
cd subdir
echo "foodata" > a_file
echo "more data" > another/other_data
git add --intent-to-add a_file
git add another/other_data
然后尝试提交:

git commit -m "Why isn't this committing anything?"
可能使用输出 我没有任何自定义挂钩(我知道):

如果重要的话,添加的文件所在的目录也是新的,并且确实如此 在之前的提交中不存在。(当我运行时,我在目录中
git状态
,请参阅提交部分中的
。)

git diff头a4dbe36e77a根据请求不输出任何内容

git show

% git show a4dbe36e77a
commit a4dbe36e77a9f3b04c2ef33de75e28b6aa7cac0c
Author: Me <john.smith@example.com>
Date:   Fri May 2 11:52:06 2014 -0700

    Why won't you commit?
为简洁起见:
git-diff--staged
显示了不同的更改:这是我希望提交的差异,但是
git-commit
没有提交。(
git diff--cached
也显示此差异。)
git commit-v
也显示此差异,但键入消息不会导致提交

这个分支唯一奇怪的地方是它是一个孤立的分支-
master
包含一个WIP,但却是这个代码的混乱版本。我本想把它清理干净,但因为我是人,所以保留了主人,担心我会删除一些东西。然而,这不是第一次提交。(第一次提交也有实际的更改。)只是现在出了问题

潜在线索/某些东西不在这里: 编辑@torek让我运行以下命令:

% git write-tree
ca9326ccba91dda7540198c082db6e6ab3fb097a
这将把索引的内容变成一棵树(然后可以将树附加到提交对象,从而生成提交)。但是,该散列与HEAD相同。考虑到我的索引中有变化,人们会认为树ID必须不同。具体而言,这些命令显示了一些奇怪的情况:

% git write-tree
ca9326ccba91dda7540198c082db6e6ab3fb097a
% git diff --staged --stat
 wsgi_util/__init__.py     |  0
 wsgi_util/api/__init__.py |  0
 wsgi_util/api/api.py      | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 wsgi_util/api/common.py   | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 wsgi_util/api/error.py    | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 235 insertions(+)
% git write-tree
ca9326ccba91dda7540198c082db6e6ab3fb097a
% git show --format=raw HEAD
commit fe28d60c21e998104e5967faf7af3bf203cd4b26
tree ca9326ccba91dda7540198c082db6e6ab3fb097a
parent f86425decfcb3410d5bc90da6ce6146e04775953
author Me <john.smith@example.com> 1399059521 -0700
committer Me <john.smith@example.com> 1399059521 -0700

    What is going on here?
还有线索吗? 因为这是一个明显的阻碍,我做了一个git重置--mixed HEAD
。然后我继续重新创建索引。其中一个文件,
wsgi\u util/\uuuuu init\uuuuu.py
不是空的,但我希望(现在)将其作为一个空文件提交:其中没有有用的代码。为此,到目前为止,我运行了
gitadd--intent来添加wsgi\u util/\uuu init\uuuu.py
。我无法提交此索引


但是,我发现,如果我用一个空文件替换它,然后执行一个普通的git add,结果索引将提交。

文档说明了这一点——添加的意图

Record only the fact that the path will be added later. An entry for the path is placed in
the index with no content. This is useful for, among other things, showing the unstaged
content of such files with git diff and committing them with git commit -a
你可以在这里自己阅读。


根据我对文档的理解和自己的实验,您需要使用git commit-a来添加文件。

只是为了澄清-您没有任何自定义钩子,对吗?@芥末:没有,没有自定义钩子。@torek(@here)可以
git-意图添加
产生这种行为吗?我有一个以这种方式添加的文件(只是为了让它是空的:我不关心当前的内容);重置索引而不运行
git--intent to add
会导致创建提交。@Thanatos:git--intent to add explainion from:仅记录稍后将添加路径的事实。路径的条目放置在索引中,没有内容。我们的期望是,这些文件将在以后准备提交时显式添加。很抱歉,由于同时读取的内容太多,有两个不同的局部变量,一个在
git add
中,另一个在
cache tree.c
本身中。无论如何,缓存树中的一个会导致它->entry\u count设置为-1,这不仅会剥离文件,而且显然还会剥离目录中的所有其他文件。这可能是一个错误。。。
% git show a4dbe36e77a
commit a4dbe36e77a9f3b04c2ef33de75e28b6aa7cac0c
Author: Me <john.smith@example.com>
Date:   Fri May 2 11:52:06 2014 -0700

    Why won't you commit?
% git show --format=raw a4dbe36e77a
commit a4dbe36e77a9f3b04c2ef33de75e28b6aa7cac0c
tree ca9326ccba91dda7540198c082db6e6ab3fb097a
parent 1842d56d5a47ff33bd420a5014f208c85acc5a1f
author Me <john.smith@example.com> 1399056726 -0700
committer Me <john.smith@example.com> 1399056726 -0700

    Why won't you commit?
% git ls-tree --full-tree ca9326ccba91dda7540198c082db6e6ab3fb097a
100644 blob fab05d167a3f8ef9ddf00d7af09e00eea03f1d28    requirements.txt
040000 tree 0d9742d9c1728495d600bde05a7f276f3c65d96d    status
% git write-tree
ca9326ccba91dda7540198c082db6e6ab3fb097a
% git write-tree
ca9326ccba91dda7540198c082db6e6ab3fb097a
% git diff --staged --stat
 wsgi_util/__init__.py     |  0
 wsgi_util/api/__init__.py |  0
 wsgi_util/api/api.py      | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 wsgi_util/api/common.py   | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 wsgi_util/api/error.py    | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 235 insertions(+)
% git write-tree
ca9326ccba91dda7540198c082db6e6ab3fb097a
% git show --format=raw HEAD
commit fe28d60c21e998104e5967faf7af3bf203cd4b26
tree ca9326ccba91dda7540198c082db6e6ab3fb097a
parent f86425decfcb3410d5bc90da6ce6146e04775953
author Me <john.smith@example.com> 1399059521 -0700
committer Me <john.smith@example.com> 1399059521 -0700

    What is going on here?
100644 fab05d167a3f8ef9ddf00d7af09e00eea03f1d28 0   requirements.txt
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0   status/__init__.py
100644 923b97d0d9e6c68e77751bb4e7fb14c41fa9d71a 0   status/api/__init__.py
100644 75f064fc9c170b56545c6b92958b38c10260beec 0   status/api/message.py
100644 07cf4dc004231945847e9f93e3de214dd02c3661 0   status/api/message_db.py
100644 78cda37dcc7a4b4f34089b2d843a9abfcd4118cf 0   status/server.py
100644 bee7c1eb7b92ccf6b78c7dfc5f36e71b77ec5792 0   status/util.py
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0   wsgi_util/__init__.py
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0   wsgi_util/api/__init__.py
100644 e92f248874be5beec7b18228d4bf0d062b508916 0   wsgi_util/api/api.py
100644 68a5a62034d52684222c7075f59f2927c1d8695e 0   wsgi_util/api/common.py
100644 28d9add6dae84ddab293e3a44cac4824f8d2d482 0   wsgi_util/api/error.py
Record only the fact that the path will be added later. An entry for the path is placed in
the index with no content. This is useful for, among other things, showing the unstaged
content of such files with git diff and committing them with git commit -a