English 中文(简体)
开始在Gite跟踪档案,而不在索引中添加
原标题:Start tracking a file in Git without adding it to the index
  • 时间:2012-04-18 15:48:55
  •  标签:
  • git

能否在不将档案列入索引的情况下开始对文件进行跟踪?

我有新档案,我想在<代码>git Clean上保存,但有可能在下一个承诺期之前发生变化。 现在我是否在指数中加入,然后在承诺之前再次加入?

最佳回答

请参看<代码>git 添加——intent-to-add(或git 添加-N。 https://git-scm.com/docs/git-add#git-add-N"rel=“noreferer”

-N
--intent-to-add

只记录这条路稍后会增加这一事实。 这条道路的条目被列入无内容的指数。 除其他外,这尤其有助于显示这些档案的未变内容,包括<条码>git diff,并以<条码>表示承诺。

See the What does git add --intent-to-add or -N do and when should it be used? question for more information.

问题回答

可在发射前使用<代码>git 添加,然后git reset

<代码>add-N(i-t-a,“intent to Add”,目的是“开始在Gite跟踪一个档案,而不添加索引”:

由于意图上加一条目的实施细节,

  • the current "git diff" (i.e. no treeish or --cached argument) would show the changes in the i-t-a file, but it does not mark the file as new,
  • while "diff --cached" would mark the file as new while showing its content as empty.

Git 2.19 (Q3 2018) changes that; since "git diff" compares the index and the working tree.
For paths added with intent-to-add bit, the command shows the full contents of them as added, but the paths themselves were not marked as new files.
They are now shown as new by default.

See commit cff5dc0, commit 8fc8f05, commit 0231ae7, commit ba4e356 (26 May 2018) by Nguyễn Thái Ngọc Duy (pclouds).
(Merged by Junio C Hamano -- gitster -- in commit ac997db, 25 Jun 2018)

在Gite 2.19之前:

$ git diff                      | $ diff --cached
--------------------------------|-------------------------------
 diff --git a/new b/new         | diff --git a/new b/new
 index e69de29..5ad28e2 100644  | new file mode 100644
 --- a/new                      | index 0000000..e69de29
 +++ b/new                      |
 @@ -0,0 +1 @@                  |
 +haha                          |

One evidence of the current output being wrong is that, the output from "git diff" (with ita entries) cannot be applied because it assumes empty files exist before applying.

2.1 See on -ita-invisible-in-index (,git diff-capple/code>改为“git diff

$ git diff                      | $ diff --cached
--------------------------------|-------------------------------
 diff --git a/new b/new         |
 new file mode 100644           |
 index 0000000..5ad28e2         |
 --- /dev/null                  |
 +++ b/new                      |
 @@ -0,0 +1 @@                  |
 +haha                          |

This option is on by default in git-status but we need more fixup in rename detection code (commit bc3dca0, Jan. 2018, Git 2.17.0). Luckily we don t need to do anything else for the rename detection code in diff.c (wt-status.c uses a customized one).


git diff-files” 教授Gite 2.28(Q32020)说,标明“意向”的道路是新的档案,没有从空洞的布道上改动。

See commit feea694 (20 Jun 2020) by Srinidhi Kaushik (clickyotomy).
(Merged by Junio C Hamano -- gitster -- in commit 298d704, 29 Jun 2020)

diff-files: treat "i-t-a" files as "not-in-index"

临时代办

The diff-files command and related commands which call the function cmd_diff_files() , consider the "intent-to-add" files as a part of the index when comparing the work-tree against it.
This was previously addressed in commits 0231ae71d3 (diff: turn --ita-invisible-in-index on by default, 2018-05-26) and 425a28e0a4 (diff-lib: allow ita entries treated as "not yet exist in index", 2016-10-24) by turning the option --ita-invisible-in-index (introduced in b42b451919 ("diff: add --ita-[in]visible-in-index", 2016-10-24, Git v2.11.0-rc0 -- merge) on by default.

<编码>diff-files (and add -p, as a result) to show i-t-a file as new,ita_invisible_in_index will be found as well as otherwise.


Warning: if you are using exclusion (lowercase) and inclusion (uppercase) in a git diff-filter, use Git 2.36 (Q2 2022).





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签