我试图做出一些改变,但是他们被遗忘了,因为 我不明白的原因:
我看一下当前的回购状态:
% 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
凌乱,但索引中的内容是我想提交的内容。 (注意:有 没有上演的变化:我不对提交这些变更感兴趣。该 &#34;变更承诺&#34;是我想要的变化 承诺。)我承诺:
% git commit -m "Why won't you commit?"
[new-master a4dbe36] Why won't you commit?
立即重新运行状态,见证一切都没有改变:
% 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 log -n1 -p
commit a4dbe36e77a9f3b04c2ef33de75e28b6aa7cac0c
Author: Me <john.smith@example.com>
Date: Fri May 2 11:52:06 2014 -0700
Why won't you commit?
这里发生了什么? 为什么没有提交这些更改?
mkdir bar && cd bar
git init
echo "data." > some_existing_file
git add some_existing_file
git commit -m "Initial commit."
刚刚成立。现在真正的乐趣。我得到了时髦的行为
--intent-to-add
(我可能只是不明白它的作用),但这再现了
我的完整问题:
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?"
我没有任何自定义挂钩(我很清楚):
% ls "`git rev-parse --git-dir`"/hooks
applypatch-msg.sample pre-applypatch.sample pre-rebase.sample
commit-msg.sample pre-commit.sample prepare-commit-msg.sample
post-update.sample pre-push.sample update.sample
如果重要,添加的文件所在的目录也是新的,并且确实如此
在前面的提交中不存在。 (当我跑的时候,我在目录本身
git status
,请参阅not-staged-for-commit部分中的..
。)
git diff HEAD 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?
同样,在raw:
% 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?
该树的ls-tree
:
% git ls-tree --full-tree ca9326ccba91dda7540198c082db6e6ab3fb097a
100644 blob fab05d167a3f8ef9ddf00d7af09e00eea03f1d28 requirements.txt
040000 tree 0d9742d9c1728495d600bde05a7f276f3c65d96d status
为简洁起见: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 ls-files -s
,似乎相关:
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
因为这种情况越来越严重,我做了git reset --mixed HEAD
。然后我继续重新创建索引。其中一个文件wsgi_util/__init__.py
不是空的,但我希望将它(现在)作为一个空文件提交:那里没有有用的代码。为此,我到目前为止已经git add --intent-to-add wsgi_util/__init__.py
了。我不能提交这个索引。
但是,我发现如果我用空文件替换它,然后执行正常的git add
,则生成的索引将提交。
答案 0 :(得分:1)
文档说明了--intent-to-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
你可以在这里阅读。 https://www.kernel.org/pub/software/scm/git/docs/git-add.html
根据我对文档的理解和自我实验,您需要使用 git commit -a 来添加文件。