Start tracking file in Git without adding to index

Is it possible to start tracking files in git without adding them to the index?

I have new files that I would like to survive git clean, but most likely will change before the next commit. Will I just add them to the index now and then add them later just before committing?

+5
source share
3 answers

It looks like you are looking for git add --intent-to-add(or git add -N). From the official git adddocumentation :

-N
--intent-to-add

, . . , , git diff git commit -a git commit -a.

, git add --intent-to -a dd -N ? .

+3

git add, git reset .

+3

add -N (, " ", " Git ") , :

- ,

  • " git diff " (.. treeish --cached) ita, ,
  • " diff --cached " diff --cached , .

Git 2.19 (Q3 2018) ; " git diff " .
, intent-to-add, , .
.

. cff5dc0, 8fc8f05, 0231ae7, ba4e356 (26 2018 .) (pclouds).
( Junio C Hamano - gitster - ac997db, 25 2018 .)

Git 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                          |

, , , " git diff " ( ita) , , .

Enabling --ita-invisible-in-index( commit 425a28e , commit b42b451 Oct. 2016, Git 2.11.0) will fix this. As a result, the line "new file" goes from " git diff --cached" to " 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 enabled by default, git-statusbut we need more corrections in the rename detection code ( commit bc3dca0, January 2018, Git 2.17.0 ). Fortunately, we don’t need to do anything for the rename detection code in diff.c( wt-status.cuses customized).

0
source

All Articles