Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start tracking a file in Git without adding to to the index

Tags:

git

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

I have new files which I'd like to survive a git clean, but will likely change before the next commit. Do I simply add them to the index now, and then add them again later just before the commit?

like image 216
ajwood Avatar asked Apr 18 '12 15:04

ajwood


People also ask

How do I start tracking a file in git?

When you start a new repository, you typically want to add all existing files so that your changes will all be tracked from that point forward. So, the first command you'll typically type is "git add ." (the "." means, this directory. So, it will add everything in this directory.) I'll type "git add ." and press Enter.

How do I start tracking untracked files in git?

You have to add the untracked files of the repository by using the “git add” command and run the “git stash” command to save the untracked file and clean the current directory for working by removing the untracked file from the repository folder.

Which command begins tracking of a new file?

Tracking New Files The git add command takes a path name for either a file or a directory; if it's a directory, the command adds all the files in that directory recursively.

Does git add only tracked files?

adds both tracked and untracked files. Let's demonstrate this, by creating a file in the current directory as well as a file in a sub-directory. Now let's change into the sub-directory and run git add . If we run git status , we'll notice only the file in the sub-directory was added.


2 Answers

Seems like you're looking for git add --intent-to-add (or git add -N). From the official git add documentation:

-N
--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.

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

like image 142
Wiktor Czajkowski Avatar answered Sep 28 '22 09:09

Wiktor Czajkowski


You can stage the files using git add, then git reset them prior to the commit.

like image 37
Fred Foo Avatar answered Sep 28 '22 08:09

Fred Foo