为了有效地(并按预期)使用 git,我进行了小的原子提交,而我确实有更长的会话,我所做的不仅仅是一件事。因此,我大量使用git add -p
。不过,这不适用于全新的文件,因为我以后往往会忘记它们。
我想做的是告诉git
那里is一个新文件,我希望它能够跟踪,但是不上演:
示例:跑步git status
产生:
# On branch my-current-branch
# Your branch is ahead of 'origin/my-current-branch' by 2 commits.
#
# Changes to be committed:
#
<<STAGED SECTION>> // A
#
# 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)
#
<<UNSTAGED-YET-KNOWN SECTION>> // B
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
<<UNKNOWN SECTION>> // C
如果我有一个文件foo
在C部分,我说git add foo
它将转到 A 部分。如果我说git add -N foo
它将同时发送到 A 和 B。但是,这意味着它将包含在下一次提交中,至少因为存在一个新文件。
我希望它只出现在 B 部分,这样我以后就可以将它添加到 A 中git add -p
or git add foo
(管他呢)。
Edit
关于add -N
解决方案,这不起作用,因为如果我在说过之后尝试提交add -N
and not正确添加后,git 会抱怨,因为它不知道如何处理空文件:
foo: not added yet
error: Error building trees
使用 Git 2.5,git add -N/--intent-to-add
实际上是正确的解决方案。
新文件不会成为下一次提交的一部分。
See 提交 d95d728 https://github.com/git/git/commit/d95d728aba06a34394d15466045cbdabdada58a2作者:Nguyễn Thái Ngọc Duy (pclouds https://github.com/pclouds)(并入d0c692263 https://github.com/git/git/commit/d0c692263f453f267ddd82b90b1a2fcff9d45f5f):
diff-lib.c
:调整 diff 中 i-t-a 条目的位置
Problem:
添加的条目“git add -N
“ 提醒用户,这样他们就不会忘记在提交之前添加它们。这些条目出现在索引中,即使它们不是真实的。它们在索引中的存在会导致混乱”git status
“ 像这样:
On branch master
Changes to be committed:
new file: foo
Changes not staged for commit:
modified: foo
如果你做了一个“git commit
", "foo
“ 即使如此,也不会被包括在内
”status
“报告为”to be committed
".
解决方案:
该补丁将输出更改为
On branch master
Changes not staged for commit:
new file: foo
no changes added to commit
这意味着:
将此类路径视为“尚未添加到索引中,但 Git 已经知道它们”;
”git diff HEAD
" and "git diff --cached HEAD
“不应该谈论它们,并且”git diff
" 应该将它们显示为新的。
+ 尚未添加到索引的文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)