# "git apply" can't add new files to repo ?

6 messages from 2011-07-15 to 2011-07-15. Participants: Yang, Carlos Martín Nieto, Junio C Hamano.
Thread: https://gitlist.dev/t/27824

## Yang, 2011-07-15 19:02

Subject: "git apply" can't add new files to repo ?
Message-ID: <CAAnh3_-ayozWnHR-ViJ3zjXQvPQA1kd9spGV_TEU=-kFzBytvw@mail.gmail.com>
URL: https://gitlist.dev/e/CAAnh3_-ayozWnHR-ViJ3zjXQvPQA1kd9spGV_TEU%3D-kFzBytvw%40mail.gmail.com

```
I created a patch by "git format-patch", and this patch includes some
newly-added files.

when I got back to the original branch, and apply this patch, the new
files appear, but they are not
added to git repository, so I have to manually find all the new files
and do "git add" for each of them.


I guess there should have been a way to automatically do "git add" for
all the new files in the patch,
how could I do that?

thanks a lot
Yang

```

## Carlos Martín Nieto, 2011-07-15 19:34

Subject: Re: "git apply" can't add new files to repo ?
Message-ID: <1310758497.7308.20.camel@centaur.lab.cmartin.tk>
URL: https://gitlist.dev/e/1310758497.7308.20.camel%40centaur.lab.cmartin.tk
In-Reply-To: <CAAnh3_-ayozWnHR-ViJ3zjXQvPQA1kd9spGV_TEU=-kFzBytvw@mail.gmail.com>

```
On Fri, 2011-07-15 at 12:02 -0700, Yang wrote:
> I created a patch by "git format-patch", and this patch includes some
> newly-added files.
> 
> when I got back to the original branch, and apply this patch, the new
> files appear, but they are not
> added to git repository, so I have to manually find all the new files
> and do "git add" for each of them.
> 
> 
> I guess there should have been a way to automatically do "git add" for
> all the new files in the patch,
> how could I do that?

git-apply is just a wrapper around the patch(1) utility. As you have
created a patch for use in an email (as that's the point of using
format-patch, so you have both the commit message and diff in one
place), you should use git-am, which takes care of all the "magic". If
you want to change what the patch does, you just need to use git commit
--amend

Cheers,
   cmn
-- 
Carlos Martín Nieto        http://www.cmartin.tk

"¿Cómo voy a decir bobadas si soy mudo?" -- CACHAI

```

## Junio C Hamano, 2011-07-15 19:39

Subject: Re: "git apply" can't add new files to repo ?
Message-ID: <7vd3hb1ggd.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vd3hb1ggd.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAAnh3_-ayozWnHR-ViJ3zjXQvPQA1kd9spGV_TEU=-kFzBytvw@mail.gmail.com>

```
Yang <teddyyyy123@gmail.com> writes:

> I created a patch by "git format-patch", and this patch includes some
> newly-added files.
>
> when I got back to the original branch, and apply this patch, the new
> files appear, but they are not
> added to git repository, so I have to manually find all the new files
> and do "git add" for each of them.

You are doing and thinking wrong.

$ git apply patch
$ git commit

would not add any new contents to existing paths either.

$ git apply --index patch
$ git commit

would be the way, but that is why we have "git am".

```

## Junio C Hamano, 2011-07-15 20:13

Subject: Re: "git apply" can't add new files to repo ?
Message-ID: <7v4o2n1evs.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v4o2n1evs.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1310758497.7308.20.camel@centaur.lab.cmartin.tk>

```
Carlos Martín Nieto <cmn@elego.de> writes:

> git-apply is just a wrapper around the patch(1) utility.

Huh?

```

## Carlos Martín Nieto, 2011-07-15 20:21

Subject: Re: "git apply" can't add new files to repo ?
Message-ID: <1310761272.7308.26.camel@centaur.lab.cmartin.tk>
URL: https://gitlist.dev/e/1310761272.7308.26.camel%40centaur.lab.cmartin.tk
In-Reply-To: <7v4o2n1evs.fsf@alter.siamese.dyndns.org>

```
On Fri, 2011-07-15 at 13:13 -0700, Junio C Hamano wrote:
> Carlos Martín Nieto <cmn@elego.de> writes:
> 
> > git-apply is just a wrapper around the patch(1) utility.
> 
> Huh?

That was a thinko; I've always considered git-apply to be little more
than patch(1), but it does look like it does much more. I should have
re-looked at the man page earlier.

Sorry for the noise,
   cmn

```

## Yang, 2011-07-15 23:00

Subject: Re: "git apply" can't add new files to repo ?
Message-ID: <CAAnh3__UeYTjk4U=s2PZkUoV7SvE440zq-qmwoLxoodisTrZ=A@mail.gmail.com>
URL: https://gitlist.dev/e/CAAnh3__UeYTjk4U%3Ds2PZkUoV7SvE440zq-qmwoLxoodisTrZ%3DA%40mail.gmail.com
In-Reply-To: <7vd3hb1ggd.fsf@alter.siamese.dyndns.org>

```
thanks all for your replies.

yang

On Fri, Jul 15, 2011 at 12:39 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Yang <teddyyyy123@gmail.com> writes:
>
>> I created a patch by "git format-patch", and this patch includes some
>> newly-added files.
>>
>> when I got back to the original branch, and apply this patch, the new
>> files appear, but they are not
>> added to git repository, so I have to manually find all the new files
>> and do "git add" for each of them.
>
> You are doing and thinking wrong.
>
> $ git apply patch
> $ git commit
>
> would not add any new contents to existing paths either.
>
> $ git apply --index patch
> $ git commit
>
> would be the way, but that is why we have "git am".
>

```
