threads / discuss / 31017

Don't share anything but those files

Subject: Don't share anything but those files

## tl;dr

8 messages between Jul 13, 2012 and Jul 16, 2012.

replies: 7people: 4as markdown or json

Yves Perron· Jul 13, 2012, 14:59 UTC · lore
Greetings everyone,

I'm wondering how to commit only selected files/folders on GIT, if even possible. Note, the ignore list is not a good option for me as I'd like to add a few files in a folder that contains many hundreds for instance.

Basically, I'm looking for a way to say, don't share anything but those files.

thx
Edward Toroshchin· Jul 13, 2012, 15:21 UTC · re: Yves Perron · lore

Re: Don't share anything but those files

On Fri, Jul 13, 2012 at 10:59:55AM -0400, Yves Perron wrote:
> I'm wondering how to commit only selected files/folders on GIT, if even 
> possible.
Just "git add" only the files you need.

If you want git to ignore all the rest, you can write '*' in your .gitignore

-- 
Edward "Hades" Toroshchin
dr_lepper on irc.freenode.org
Illia Bobyr· Jul 13, 2012, 18:08 UTC · re: Edward Toroshchin · lore

Re: Don't share anything but those files

On 7/13/2012 8:21 AM, Edward Toroshchin wrote:
Show 7 quoted lines
> On Fri, Jul 13, 2012 at 10:59:55AM -0400, Yves Perron wrote:
>> I'm wondering how to commit only selected files/folders on GIT, if even
>> possible.
> Just "git add" only the files you need.
>
> If you want git to ignore all the rest, you can write '*' in your
> .gitignore

As an alternative, you may be able to use negative patterns in your .gitignore or other ignore files. Like this:

* !.gitignore !a_file_that_should_be_tracked !a_dir_to_track/

See "git help ignore" for more details.
Illia Bobyr
Yves Perron· Jul 13, 2012, 18:19 UTC · re: Illia Bobyr · lore

Re: Don't share anything but those files

On 7/13/2012 2:08 PM, Illia Bobyr wrote:
> *
> !.gitignore
> !a_file_that_should_be_tracked
> !a_dir_to_track/
That is exactly what i was hoping for,
thank you everyone!
Yves Perron· Jul 16, 2012, 14:26 UTC · re: Yves Perron · lore

Re: Don't share anything but those files

Greetings everyone,

After investigation, the solution turns out to solve the problem partially. What is does is it update any existing files/folders already present but does not actually add new ones. So my question is, could the content of "what to add" be edited directly? Where is the actual registry of added files/folders to synchronize if any?

Show 9 quoted lines
> On 7/13/2012 2:08 PM, Illia Bobyr wrote:
>> *
>> !.gitignore
>> !a_file_that_should_be_tracked
>> !a_dir_to_track/
>
> That is exactly what i was hoping for,
>
> thank you everyone!
Edward Toroshchin· Jul 13, 2012, 16:14 UTC · lore

Re: Don't share anything but those files

On Fri, Jul 13, 2012 at 11:35:36AM -0400, Yves Perron wrote:
Show 7 quoted lines
> Oh I see, thank you for your response,
> 
> Can I put all the folders/files I want to add in a config file so I 
> don't have to do this every time?
> 
> Thx
> 

You won't have to do this every time. Once you add a file and commit it, git will track it in the future.

-- 
Edward "Hades" Toroshchin
dr_lepper on irc.freenode.org
Yves Perron· Jul 13, 2012, 17:40 UTC · re: Edward Toroshchin · lore

Re: Don't share anything but those files

Ok, let me rephrase, is there a way to edit a file where we can put every files/folders we need to add without the need of entering a command for each entry?

On 7/13/2012 12:14 PM, Edward Toroshchin wrote:
Show 11 quoted lines
> On Fri, Jul 13, 2012 at 11:35:36AM -0400, Yves Perron wrote:
>> Oh I see, thank you for your response,
>>
>> Can I put all the folders/files I want to add in a config file so I
>> don't have to do this every time?
>>
>> Thx
>>
> You won't have to do this every time. Once you add a file and commit it,
> git will track it in the future.
>
--
Taylor Hedberg· Jul 13, 2012, 17:53 UTC · re: Yves Perron · lore

Re: Don't share anything but those files

Yves Perron, Fri 2012-07-13 @ 13:40:56-0400:
> Ok, let me rephrase, is there a way to edit a file where we can put
> every files/folders we need to add without the need of entering a
> command for each entry?

Sure, but you don't need functionality built in to Git to do this. Just list the paths you want to add in a file and then:

    xargs git add <filename

But you only have to do this once, so I'm not really sure what that buys you.

You can use glob patterns to select groups of files to add as well, if there is some similarity in the pathnames.

← back to recent threads