{"thread":{"id":"29644","subject":"Identify Commit ID from an Extracted Source Snapshot","startedAt":"2012-02-16T22:06:55Z","lastAt":"2012-02-17T00:14:57Z","messageCount":6,"participants":["James Walmsley","Michael Schubert","Sam Vilain","Jonathan Nieder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"184845","messageId":"BEDA323D25EF6045A68DAB9FD91A0BF123A85B38@DB3PRD0402MB118.eurprd04.prod.outlook.com","threadId":"29644","inReplyTo":null,"subject":"Identify Commit ID from an Extracted Source Snapshot","fromName":"James Walmsley","fromEmail":"james@fullfat-fs.co.uk","sentAt":"2012-02-16T22:06:55Z","receivedAt":"2012-02-16T22:06:55Z","isPatch":false,"sender":{"key":"james@fullfat-fs.co.uk","avatar":null},"body":"Hi\n\nI couldn't find this on google, and I have no idea if its even possible. I have several zip files from previous versions of my source code. (I imported svn into git).\nI would like to add TAGS to git which represent the versions based on the files in my zip archives.\n\nDoes anyone know how to do this?\n\nThanks for any help in advance,\n\nGIT is amazing!\n\nJames Walmsley\n"},{"id":"184848","messageId":"4F3D8A7C.2020400@elegosoft.com","threadId":"29644","inReplyTo":"BEDA323D25EF6045A68DAB9FD91A0BF123A85B38@DB3PRD0402MB118.eurprd04.prod.outlook.com","subject":"Re: Identify Commit ID from an Extracted Source Snapshot","fromName":"Michael Schubert","fromEmail":"mschub@elegosoft.com","sentAt":"2012-02-16T23:00:12Z","receivedAt":"2012-02-16T23:00:12Z","isPatch":false,"sender":{"key":"mschub@elegosoft.com","avatar":null},"body":"On 02/16/2012 11:06 PM, James Walmsley wrote:\n> I couldn't find this on google, and I have no idea if its even\n> possible. I have several zip files from previous versions of my\n> source code. (I imported svn into git). I would like to add TAGS to\n> git which represent the versions based on the files in my zip\n> archives.\n> \n> Does anyone know how to do this?\n\nIf it's just about providing the ancient code together with the\n(imported) more recent history from SVN, you could create an extra\norphan branch for each zip packet, add the files, commit and\neventually tag.\n\nIf your question is more like \"how do I tell git to find out where\nthis old code fits in my history and eventually place it there\",\nthe answer is: you cannot do it. No VCS will do this and especially\nnot Git.\n"},{"id":"184850","messageId":"4F3D8EFF.9000806@vilain.net","threadId":"29644","inReplyTo":"4F3D8A7C.2020400@elegosoft.com","subject":"Re: Identify Commit ID from an Extracted Source Snapshot","fromName":"Sam Vilain","fromEmail":"sam@vilain.net","sentAt":"2012-02-16T23:19:27Z","receivedAt":"2012-02-16T23:19:27Z","isPatch":false,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"On 2/16/12 3:00 PM, Michael Schubert wrote:\n> On 02/16/2012 11:06 PM, James Walmsley wrote:\n>> I couldn't find this on google, and I have no idea if its even\n>> possible. I have several zip files from previous versions of my\n>> source code. (I imported svn into git). I would like to add TAGS to\n>> git which represent the versions based on the files in my zip\n>> archives.\n>>\n>> Does anyone know how to do this?\n>\n> If it's just about providing the ancient code together with the\n> (imported) more recent history from SVN, you could create an extra\n> orphan branch for each zip packet, add the files, commit and\n> eventually tag.\n>\n> If your question is more like \"how do I tell git to find out where\n> this old code fits in my history and eventually place it there\",\n> the answer is: you cannot do it. No VCS will do this and especially\n> not Git.\n\nOnce you've got a tree in git which corresponds to the contents of the \nzip file, you can use git diff --stat TREEID COMMITID\n\nYou can get the commitid by obtaining the most recent timestamp for a \nfile within the archive, then just using git rev-list --all --since=... \n--until=... to get a window of commit IDs, and hunt around until you \nfind the one with the smallest diff.\n\nIt's hardly a straightforward thing, usually because the contents of the \nzip file never quite match the exact contents of source control—think \nautoconf and other files generated for distribution but not stored in \nthe history.  So you need to use a fuzzy search.\n\nSam\n"},{"id":"184852","messageId":"4F3D94A1.2040706@elegosoft.com","threadId":"29644","inReplyTo":"4F3D8EFF.9000806@vilain.net","subject":"Re: Identify Commit ID from an Extracted Source Snapshot","fromName":"Michael Schubert","fromEmail":"mschub@elegosoft.com","sentAt":"2012-02-16T23:43:29Z","receivedAt":"2012-02-16T23:43:29Z","isPatch":false,"sender":{"key":"mschub@elegosoft.com","avatar":null},"body":"On 02/17/2012 12:19 AM, Sam Vilain wrote:\n> On 2/16/12 3:00 PM, Michael Schubert wrote:\n>> On 02/16/2012 11:06 PM, James Walmsley wrote:\n>>> I couldn't find this on google, and I have no idea if its even \n>>> possible. I have several zip files from previous versions of my \n>>> source code. (I imported svn into git). I would like to add TAGS\n>>> to git which represent the versions based on the files in my zip \n>>> archives.\n>>> \n>>> Does anyone know how to do this?\n>> \n>> If it's just about providing the ancient code together with the \n>> (imported) more recent history from SVN, you could create an extra \n>> orphan branch for each zip packet, add the files, commit and \n>> eventually tag.\n>> \n>> If your question is more like \"how do I tell git to find out where \n>> this old code fits in my history and eventually place it there\", \n>> the answer is: you cannot do it. No VCS will do this and\n>> especially not Git.\n> \n> Once you've got a tree in git which corresponds to the contents of\n> the zip file, you can use git diff --stat TREEID COMMITID\n> \n> You can get the commitid by obtaining the most recent timestamp for a\n> file within the archive, then just using git rev-list --all\n> --since=... --until=... to get a window of commit IDs, and hunt\n> around until you find the one with the smallest diff.\n> \n> It's hardly a straightforward thing, usually because the contents of\n> the zip file never quite match the exact contents of source\n> control—think autoconf and other files generated for distribution but\n> not stored in the history.  So you need to use a fuzzy search.\n\nI totally disregared the \"slicing and rebuilding history approach\", just\nbecause I didn't think that's what James is asking about. Could be fun.\n"},{"id":"184853","messageId":"20120216235240.GA20779@burratino","threadId":"29644","inReplyTo":"4F3D8A7C.2020400@elegosoft.com","subject":"Re: Identify Commit ID from an Extracted Source Snapshot","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-02-16T23:53:08Z","receivedAt":"2012-02-16T23:53:08Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Michael Schubert wrote:\n\n> If your question is more like \"how do I tell git to find out where\n> this old code fits in my history and eventually place it there\",\n> the answer is: you cannot do it. No VCS will do this and especially\n> not Git.\n\nWouldn't it be possible to add the tags you want by walking through\nthe commit log to find a matching commit for each tarball?\n\nFor example:\n\n\t# Usage: \"GIT_DIR=<repository> tag-tars <tarballs>\"\n\t# Arguments should be tarballs containing releases in\n\t# reverse-chronological order.\n\t# Should be run in an empty directory, which will be\n\t# used as a workspace.\n\n\t# save stdin\n\texec 3<&0\n\n\tGIT_DIR=$(git rev-parse --resolve-git-dir \"$GIT_DIR\") || exit 1\n\tGIT_INDEX_FILE=$GIT_DIR/index.tag-tars\n\texport GIT_INDEX_FILE\n\n\tif test -n \"$(git ls-files -c -o | head -1)\"\n\tthen\n\t\techo >&2 'fatal: I need an empty directory to work with'\n\t\texit 1\n\tfi\n\n\tfor tar\n\tdo\n\t\t# empty workspace\n\t\tgit ls-files | xargs rm -f --\n\t\trm -f \"$GIT_INDEX_FILE\"\n\n\t\t# get tree name for tarball\n\t\ttar --strip-components=1 -xf \"$tar\"\n\t\tgit ls-files -o | git update-index --add --stdin\n\t\ttree=$(git write-tree)\n\n\t\t# tag the first commit found matching that tree, if any\n\t\tgit rev-list master |\n\t\twhile read cmit\n\t\tdo\n\t\t\tif git diff-tree --quiet $cmit $tree\n\t\t\tthen\n\t\t\t\tgit tag -a ${tar%%.*} $cmit <&3\n\t\t\t\tbreak\n\t\t\tfi\n\t\tdone\n\tdone\n\nVariation using --numstat and a path filter to find the closest commit\nignoring some files instead of an exact match left as an exercise to\nthe reader.\n\nHope that helps,\nJonathan\n"},{"id":"184856","messageId":"4F3D9C01.5000402@elegosoft.com","threadId":"29644","inReplyTo":"20120216235240.GA20779@burratino","subject":"Re: Identify Commit ID from an Extracted Source Snapshot","fromName":"Michael Schubert","fromEmail":"mschub@elegosoft.com","sentAt":"2012-02-17T00:14:57Z","receivedAt":"2012-02-17T00:14:57Z","isPatch":false,"sender":{"key":"mschub@elegosoft.com","avatar":null},"body":"On 02/17/2012 12:53 AM, Jonathan Nieder wrote:\n> Michael Schubert wrote:\n> \n>> If your question is more like \"how do I tell git to find out where\n>> this old code fits in my history and eventually place it there\",\n>> the answer is: you cannot do it. No VCS will do this and especially\n>> not Git.\n> \n> Wouldn't it be possible to add the tags you want by walking through\n> the commit log to find a matching commit for each tarball?\n\nI read the question like \"How do I insert / prepend my zipped\n*pre-VCS* version (in)to my Git history in an automated fashion\".\n\n> For example:\n> \n> \t# Usage: \"GIT_DIR=<repository> tag-tars <tarballs>\"\n> \t# Arguments should be tarballs containing releases in\n> \t# reverse-chronological order.\n> \t# Should be run in an empty directory, which will be\n> \t# used as a workspace.\n> \n> \t# save stdin\n> \texec 3<&0\n> \n> \tGIT_DIR=$(git rev-parse --resolve-git-dir \"$GIT_DIR\") || exit 1\n> \tGIT_INDEX_FILE=$GIT_DIR/index.tag-tars\n> \texport GIT_INDEX_FILE\n> \n> \tif test -n \"$(git ls-files -c -o | head -1)\"\n> \tthen\n> \t\techo >&2 'fatal: I need an empty directory to work with'\n> \t\texit 1\n> \tfi\n> \n> \tfor tar\n> \tdo\n> \t\t# empty workspace\n> \t\tgit ls-files | xargs rm -f --\n> \t\trm -f \"$GIT_INDEX_FILE\"\n> \n> \t\t# get tree name for tarball\n> \t\ttar --strip-components=1 -xf \"$tar\"\n> \t\tgit ls-files -o | git update-index --add --stdin\n> \t\ttree=$(git write-tree)\n> \n> \t\t# tag the first commit found matching that tree, if any\n> \t\tgit rev-list master |\n> \t\twhile read cmit\n> \t\tdo\n> \t\t\tif git diff-tree --quiet $cmit $tree\n> \t\t\tthen\n> \t\t\t\tgit tag -a ${tar%%.*} $cmit <&3\n> \t\t\t\tbreak\n> \t\t\tfi\n> \t\tdone\n> \tdone\n> \n> Variation using --numstat and a path filter to find the closest commit\n> ignoring some files instead of an exact match left as an exercise to\n> the reader.\n\nNice, thanks!\n"}]}