{"thread":{"id":"20110","subject":"git-am with an initial checkin doesn't work","startedAt":"2009-07-14T14:55:34Z","lastAt":"2009-07-15T14:46:36Z","messageCount":3,"participants":["Dirk Süsserott","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"117967","messageId":"4A5C9C66.1050100@dirk.my1.cc","threadId":"20110","inReplyTo":null,"subject":"git-am with an initial checkin doesn't work","fromName":"Dirk Süsserott","fromEmail":"newsletter@dirk.my1.cc","sentAt":"2009-07-14T14:55:34Z","receivedAt":"2009-07-14T14:55:34Z","isPatch":false,"sender":{"key":"newsletter@dirk.my1.cc","avatar":null},"body":"Hi,\n\nI've a question concerning 'git am' and 'git format-patch'. It seems\nimpossible to apply the \"initial checkin\" (as generated by git\nformat-patch -N --root) to an empty repository. The following workflow\nmight clarify that:\n\n# Create a new repository with an initial checkin:\nmkdir foo && cd foo && git init\necho \"initial checkin\" > initial.checkin\ngit add initial.checkin && git commit -m \"initial checkin\"\n\n# Kinda \"export\" the repo:\ngit format-patch -1 --root; # generates 0001-initial-checkin.patch\n\n# Re-create the repository:\nrm -rf .git initial.checkin && git init\n\n# Try to \"import\" the patch:\ngit am 0001-initial-checkin.patch\n\nThe latter yields to\nfatal: HEAD: not a valid SHA1\nfatal: bad revision 'HEAD'\n\nIt works, when I\ngit apply 0001-initial-checkin.patch\ninstead of am'ing it, but then the thing isn't committed and I've to\nmanually git-commit it.\n\nIs this a bug, intentional behavior, or am I missing some magic option\nto git-am?\n\nBackground:\nI faced that problem when I tried to import some old data into Git\n(namely .tar.gz files) and wanted to start with 2 or 3 commits of my own\n(the import scripts) and then the other files on top of it. Because my\nimport scripts didn't work well at first, I had to re-, re-, and\nre-import and start over all again. To always start with a clean repo, I\nthought adding my scripts and then saving them as 000N-*.patch would be\na good idea, but the initial git-am didn't work. I know, there are other\nways (git-rebase is a big friend here), but I thought git-format-patch\nand git-am worked symmetrically. Wrong?\n\nCheers,\n    Dirk\n"},{"id":"117978","messageId":"7vocrngm2d.fsf@alter.siamese.dyndns.org","threadId":"20110","inReplyTo":"4A5C9C66.1050100@dirk.my1.cc","subject":"Re: git-am with an initial checkin doesn't work","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-07-14T18:24:10Z","receivedAt":"2009-07-14T18:24:10Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dirk Süsserott <newsletter@dirk.my1.cc> writes:\n\n> # Try to \"import\" the patch:\n> git am 0001-initial-checkin.patch\n>\n> The latter yields to\n> fatal: HEAD: not a valid SHA1\n> fatal: bad revision 'HEAD'\n>\n> It works, when I\n> git apply 0001-initial-checkin.patch\n> instead of am'ing it, but then the thing isn't committed and I've to\n> manually git-commit it.\n>\n> Is this a bug, intentional behavior, or am I missing some magic option\n> to git-am?\n\nThe original mode of operation of the e-mail patchflow commands was to\nsupport project members who contribute changes to _existing_ projects, and\nmaintainers to accept such changes.  The reason behind the behaviour you\nare observing is merely a historical accident that nobody bothered about\nuse cases outside of that original purpose.  For exactly the same reason,\nthe original implementation of format-patch did not bother with the root\ncommit.\n\nIOW, this was not an intentional behaviour, neither it was a bug.  It was\nsimply use outside of spec, and nobody bothered until f79d4c8 (git-am:\nteach git-am to apply a patch to an unborn branch, 2009-04-10), which is\nv1.6.3-rc1~11^2, added a support for it.\n\nWhat version of git are you running?\n"},{"id":"118029","messageId":"4A5DEBCC.9060600@suesserott.de","threadId":"20110","inReplyTo":"7vocrngm2d.fsf@alter.siamese.dyndns.org","subject":"Re: git-am with an initial checkin doesn't work","fromName":"Dirk Süsserott","fromEmail":"poststelle@suesserott.de","sentAt":"2009-07-15T14:46:36Z","receivedAt":"2009-07-15T14:46:36Z","isPatch":false,"sender":{"key":"poststelle@suesserott.de","avatar":null},"body":"Am 14.07.2009 20:24 schrieb Junio C Hamano:\n> Dirk Süsserott <newsletter@dirk.my1.cc> writes:\n> \n>> # Try to \"import\" the patch:\n>> git am 0001-initial-checkin.patch\n>>\n>> The latter yields to\n>> fatal: HEAD: not a valid SHA1\n>> fatal: bad revision 'HEAD'\n>>\n>> It works, when I\n>> git apply 0001-initial-checkin.patch\n>> instead of am'ing it, but then the thing isn't committed and I've to\n>> manually git-commit it.\n>>\n>> Is this a bug, intentional behavior, or am I missing some magic option\n>> to git-am?\n> \n> The original mode of operation of the e-mail patchflow commands was to\n> support project members who contribute changes to _existing_ projects, and\n> maintainers to accept such changes.  The reason behind the behaviour you\n> are observing is merely a historical accident that nobody bothered about\n> use cases outside of that original purpose.  For exactly the same reason,\n> the original implementation of format-patch did not bother with the root\n> commit.\n> \n> IOW, this was not an intentional behaviour, neither it was a bug.  It was\n> simply use outside of spec, and nobody bothered until f79d4c8 (git-am:\n> teach git-am to apply a patch to an unborn branch, 2009-04-10), which is\n> v1.6.3-rc1~11^2, added a support for it.\n> \n> What version of git are you running?\n> \n> \n\nHi Junio,\n\nI used \"1.6.1.9.g97c34\" which is an msysGit release and not exactly the \nlatest. I now updated to \"1.6.3.2.1299.gee46c\" and the problem \ndissapeared. Thanks for the hint and sorry for the noise.\n\n     -- Dirk\n"}]}