我试图做出一些改变,但由于我不明白的原因,他们被抛在了后面:
我看一下当前的回购状态:
% 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
Run Code Online (Sandbox Code Playgroud)
凌乱,但索引中的内容是我想要提交的内容.(注意:有些更改没有暂存:我对提交这些更改不感兴趣."要提交的更改"下的更改是我希望提交的更改.)我承诺:
% git commit -m "Why won't you commit?"
[new-master a4dbe36] Why won't you commit?
Run Code Online (Sandbox Code Playgroud)
并立即重新运行状态,见证一切都没有改变:
% 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
Run Code Online (Sandbox Code Playgroud)
如果我查看最后一次提交,我们可以看到没有任何内容:
% 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?
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?为什么不进行这些更改?
mkdir bar && cd bar
git init
echo "data." > some_existing_file
git add some_existing_file
git commit -m "Initial commit."
Run Code Online (Sandbox Code Playgroud)
那只是设置.现在真正的乐趣.我得到了时髦的行为
--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
Run Code Online (Sandbox Code Playgroud)
然后尝试提交:
git commit -m "Why isn't this committing anything?"
Run Code Online (Sandbox Code Playgroud)
我没有任何自定义挂钩(我知道):
% 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
Run Code Online (Sandbox Code Playgroud)
如果重要,添加的文件所在的目录也是新的,并且在前面的提交中不存在.(当我运行时,我在目录本身
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?
Run Code Online (Sandbox Code Playgroud)
同样,原始的:
% 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?
Run Code Online (Sandbox Code Playgroud)
的ls-tree
那棵树:
% git ls-tree --full-tree ca9326ccba91dda7540198c082db6e6ab3fb097a
100644 blob fab05d167a3f8ef9ddf00d7af09e00eea03f1d28 requirements.txt
040000 tree 0d9742d9c1728495d600bde05a7f276f3c65d96d status
Run Code Online (Sandbox Code Playgroud)
为简洁起见:git diff --staged
显示了变化的差异:这是我希望提交的差异,但这git commit
不是提交.(git diff --cached
也显示了这个差异.)git commit -v
也显示了这个差异,但输入消息不会导致提交.
关于这个分支唯一真正奇怪的是它是一个孤立的分支 - master
包含WIP,但是这个代码的混乱版本.我希望能够清理它,但保留主人因为我是人类,并担心我会删除一些东西.但是,这不是第一次提交.(第一次提交也有实际的改变.)现在才出现问题.
编辑 @torek让我运行这个:
% git write-tree
ca9326ccba91dda7540198c082db6e6ab3fb097a
Run Code Online (Sandbox Code Playgroud)
这应该将索引的内容转换为树(然后可以将其附加到提交对象,因此提交就会生成).但是,该哈希与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?
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
因为这在路上显着增加,我做了一个git reset --mixed HEAD
.然后我继续重新创建索引.其中一个文件wsgi_util/__init__.py
不是空的,但我希望将它(现在)作为一个空文件提交:那里没有有用的代码.为此,我到目前为止已经开始了git add --intent-to-add wsgi_util/__init__.py
.我不能提交这个索引.
但是,我发现如果我用空文件替换它,然后执行正常操作git add
,结果索引将提交.
该文档说明了这一点 --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
Run Code Online (Sandbox Code Playgroud)
您可以在这里自行阅读。 https://www.kernel.org/pub/software/scm/git/docs/git-add.html
根据我对文档的理解和自己的实验,您需要使用git commit -a来添加文件。