git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to add folder NON RECURSIVELY ?

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Apr 3, 2012, 12:08 UTC
Message-ID
<vpqzkatc915.fsf@bauges.imag.fr>
In-Reply-To
<20120403173111.5329d7ed@shiva.selfip.org>
"J. Bakshi" <joydeep.bakshi@infoservices.in> writes:
> I like to add the folder structure in a way that only foo/dir1/file1 is added to
> the git. foo/dir2 and foo/dir3 should be added to the git also to show
> the directory
> structure and not the contents of those folder.

Git doesn't record the existance of directories. For Git, a directory exists if and only if it has some files in it. So, "foo/dir2 and foo/dir3 should be added to the git" cannot be done in Git.

A common workaround is to create a dummy file, typically .gitignore, within the directories you want to add. Depending on the intended use of the directory, you may want this file to be empty (to tell your collaborators "there's nothing here for now, but there will be later"), or to contain '*' to mean "there will never be any tracked files in this directory".

IOW,

touch foo/dir2/.gitignore foo/dir3/.gitignore git add foo/dir2/.gitignore foo/dir3/.gitignore

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: J. BakshiNext: J. Bakshi
Message 2 of 6 in “How to add folder NON RECURSIVELY ?”
  1. J. BakshiApr 3, 2012
  2. Matthieu MoyApr 3, 2012
  3. J. BakshiApr 3, 2012
  4. Dirk SüsserottApr 3, 2012
  5. Matthieu MoyApr 3, 2012
  6. J. BakshiApr 4, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.