{"thread":{"id":"27824","subject":"\"git apply\" can't add new files to repo ?","startedAt":"2011-07-15T19:02:19Z","lastAt":"2011-07-15T23:00:07Z","messageCount":6,"participants":["Yang","Carlos Martín Nieto","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"171419","messageId":"CAAnh3_-ayozWnHR-ViJ3zjXQvPQA1kd9spGV_TEU=-kFzBytvw@mail.gmail.com","threadId":"27824","inReplyTo":null,"subject":"\"git apply\" can't add new files to repo ?","fromName":"Yang","fromEmail":"teddyyyy123@gmail.com","sentAt":"2011-07-15T19:02:19Z","receivedAt":"2011-07-15T19:02:19Z","isPatch":false,"sender":{"key":"teddyyyy123@gmail.com","avatar":null},"body":"I created a patch by \"git format-patch\", and this patch includes some\nnewly-added files.\n\nwhen I got back to the original branch, and apply this patch, the new\nfiles appear, but they are not\nadded to git repository, so I have to manually find all the new files\nand do \"git add\" for each of them.\n\n\nI guess there should have been a way to automatically do \"git add\" for\nall the new files in the patch,\nhow could I do that?\n\nthanks a lot\nYang\n"},{"id":"171422","messageId":"1310758497.7308.20.camel@centaur.lab.cmartin.tk","threadId":"27824","inReplyTo":"CAAnh3_-ayozWnHR-ViJ3zjXQvPQA1kd9spGV_TEU=-kFzBytvw@mail.gmail.com","subject":"Re: \"git apply\" can't add new files to repo ?","fromName":"Carlos Martín Nieto","fromEmail":"cmn@elego.de","sentAt":"2011-07-15T19:34:57Z","receivedAt":"2011-07-15T19:34:57Z","isPatch":false,"sender":{"key":"cmn@elego.de","avatar":"https://avatars.githubusercontent.com/u/335443?v=4"},"body":"On Fri, 2011-07-15 at 12:02 -0700, Yang wrote:\n> I created a patch by \"git format-patch\", and this patch includes some\n> newly-added files.\n> \n> when I got back to the original branch, and apply this patch, the new\n> files appear, but they are not\n> added to git repository, so I have to manually find all the new files\n> and do \"git add\" for each of them.\n> \n> \n> I guess there should have been a way to automatically do \"git add\" for\n> all the new files in the patch,\n> how could I do that?\n\ngit-apply is just a wrapper around the patch(1) utility. As you have\ncreated a patch for use in an email (as that's the point of using\nformat-patch, so you have both the commit message and diff in one\nplace), you should use git-am, which takes care of all the \"magic\". If\nyou want to change what the patch does, you just need to use git commit\n--amend\n\nCheers,\n   cmn\n-- \nCarlos Martín Nieto        http://www.cmartin.tk\n\n\"¿Cómo voy a decir bobadas si soy mudo?\" -- CACHAI\n"},{"id":"171424","messageId":"7vd3hb1ggd.fsf@alter.siamese.dyndns.org","threadId":"27824","inReplyTo":"CAAnh3_-ayozWnHR-ViJ3zjXQvPQA1kd9spGV_TEU=-kFzBytvw@mail.gmail.com","subject":"Re: \"git apply\" can't add new files to repo ?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-07-15T19:39:30Z","receivedAt":"2011-07-15T19:39:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Yang <teddyyyy123@gmail.com> writes:\n\n> I created a patch by \"git format-patch\", and this patch includes some\n> newly-added files.\n>\n> when I got back to the original branch, and apply this patch, the new\n> files appear, but they are not\n> added to git repository, so I have to manually find all the new files\n> and do \"git add\" for each of them.\n\nYou are doing and thinking wrong.\n\n$ git apply patch\n$ git commit\n\nwould not add any new contents to existing paths either.\n\n$ git apply --index patch\n$ git commit\n\nwould be the way, but that is why we have \"git am\".\n"},{"id":"171429","messageId":"7v4o2n1evs.fsf@alter.siamese.dyndns.org","threadId":"27824","inReplyTo":"1310758497.7308.20.camel@centaur.lab.cmartin.tk","subject":"Re: \"git apply\" can't add new files to repo ?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-07-15T20:13:27Z","receivedAt":"2011-07-15T20:13:27Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Carlos Martín Nieto <cmn@elego.de> writes:\n\n> git-apply is just a wrapper around the patch(1) utility.\n\nHuh?\n"},{"id":"171431","messageId":"1310761272.7308.26.camel@centaur.lab.cmartin.tk","threadId":"27824","inReplyTo":"7v4o2n1evs.fsf@alter.siamese.dyndns.org","subject":"Re: \"git apply\" can't add new files to repo ?","fromName":"Carlos Martín Nieto","fromEmail":"cmn@elego.de","sentAt":"2011-07-15T20:21:12Z","receivedAt":"2011-07-15T20:21:12Z","isPatch":false,"sender":{"key":"cmn@elego.de","avatar":"https://avatars.githubusercontent.com/u/335443?v=4"},"body":"On Fri, 2011-07-15 at 13:13 -0700, Junio C Hamano wrote:\n> Carlos Martín Nieto <cmn@elego.de> writes:\n> \n> > git-apply is just a wrapper around the patch(1) utility.\n> \n> Huh?\n\nThat was a thinko; I've always considered git-apply to be little more\nthan patch(1), but it does look like it does much more. I should have\nre-looked at the man page earlier.\n\nSorry for the noise,\n   cmn\n"},{"id":"171446","messageId":"CAAnh3__UeYTjk4U=s2PZkUoV7SvE440zq-qmwoLxoodisTrZ=A@mail.gmail.com","threadId":"27824","inReplyTo":"7vd3hb1ggd.fsf@alter.siamese.dyndns.org","subject":"Re: \"git apply\" can't add new files to repo ?","fromName":"Yang","fromEmail":"teddyyyy123@gmail.com","sentAt":"2011-07-15T23:00:07Z","receivedAt":"2011-07-15T23:00:07Z","isPatch":false,"sender":{"key":"teddyyyy123@gmail.com","avatar":null},"body":"thanks all for your replies.\n\nyang\n\nOn Fri, Jul 15, 2011 at 12:39 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Yang <teddyyyy123@gmail.com> writes:\n>\n>> I created a patch by \"git format-patch\", and this patch includes some\n>> newly-added files.\n>>\n>> when I got back to the original branch, and apply this patch, the new\n>> files appear, but they are not\n>> added to git repository, so I have to manually find all the new files\n>> and do \"git add\" for each of them.\n>\n> You are doing and thinking wrong.\n>\n> $ git apply patch\n> $ git commit\n>\n> would not add any new contents to existing paths either.\n>\n> $ git apply --index patch\n> $ git commit\n>\n> would be the way, but that is why we have \"git am\".\n>\n"}]}