From: "Dirk Süsserott" <newsletter@dirk.my1.cc>
To: "J. Bakshi" <joydeep.bakshi@infoservices.in>
Cc: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>, git@vger.kernel.org
Subject: Re: How to add folder NON RECURSIVELY ?
Date: Tue, 03 Apr 2012 15:12:32 +0200 [thread overview]
Message-ID: <4F7AF740.9070906@dirk.my1.cc> (raw)
In-Reply-To: <201204031223.q33CMvQC004186@VM-MailSafe-02.soltecsis.com>
Am 03.04.2012 14:22 schrieb J. Bakshi:
> On Tue, 03 Apr 2012 14:08:38 +0200
> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:
>
>> "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
>>
>
> Thanks for your suggestion.
> So .gitignore for foo/dir2/ and foo/dir3/ should add those directories non recursively.
>
> Could you please suggest how can I add foo/dir1/file1 ?
>
> guess
>
> touch foo/dir1/.gitignore
> git add foo/dir1/
> git add foo/dir1/file1
>
Almost ;-)
Since foo/dir1 already contains file1 there's no need to add a
.gitignore in dir1 (except, of course, you really want to ignore sth. in
that directory).
If this is your directory structure:
foo/dir1/file1
foo/dir2
foo/dir3
foo/dir1/ is automatically added when you "git add foo/dir1/file1".
To add the (empty) directories dir2 and dir3 you need some placeholder
file in them because git does not track directories, only files
(together with their path).
Thus:
touch foo/dir2/.gitignore
touch foo/dir3/.gitignore
git add foo/dir2/.gitignore
git add foo/dir3/.gitignore
If you add a directory (like "git add foo/dir1/) git will add all files
in that directory (recursively), again, except for empty directories.
HTH,
Dirk
next prev parent reply other threads:[~2012-04-03 13:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-03 12:01 How to add folder NON RECURSIVELY ? J. Bakshi
2012-04-03 12:08 ` Matthieu Moy
2012-04-03 12:22 ` J. Bakshi
2012-04-03 13:12 ` Dirk Süsserott [this message]
2012-04-03 13:15 ` Matthieu Moy
2012-04-04 6:52 ` J. Bakshi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F7AF740.9070906@dirk.my1.cc \
--to=newsletter@dirk.my1.cc \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=git@vger.kernel.org \
--cc=joydeep.bakshi@infoservices.in \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).