git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Identify Commit ID from an Extracted Source Snapshot

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Feb 16, 2012, 23:53 UTC
Message-ID
<20120216235240.GA20779@burratino>
In-Reply-To
<4F3D8A7C.2020400@elegosoft.com>
Michael Schubert wrote:
> If your question is more like "how do I tell git to find out where
> this old code fits in my history and eventually place it there",
> the answer is: you cannot do it. No VCS will do this and especially
> not Git.

Wouldn't it be possible to add the tags you want by walking through the commit log to find a matching commit for each tarball?

For example:
	# Usage: "GIT_DIR=<repository> tag-tars <tarballs>"
	# Arguments should be tarballs containing releases in
	# reverse-chronological order.
	# Should be run in an empty directory, which will be
	# used as a workspace.
	# save stdin
	exec 3<&0
	GIT_DIR=$(git rev-parse --resolve-git-dir "$GIT_DIR") || exit 1
	GIT_INDEX_FILE=$GIT_DIR/index.tag-tars
	export GIT_INDEX_FILE
	if test -n "$(git ls-files -c -o | head -1)"
	then
		echo >&2 'fatal: I need an empty directory to work with'
		exit 1
	fi
	for tar
	do
		# empty workspace
		git ls-files | xargs rm -f --
		rm -f "$GIT_INDEX_FILE"
		# get tree name for tarball
		tar --strip-components=1 -xf "$tar"
		git ls-files -o | git update-index --add --stdin
		tree=$(git write-tree)
		# tag the first commit found matching that tree, if any
		git rev-list master |
		while read cmit
		do
			if git diff-tree --quiet $cmit $tree
			then
				git tag -a ${tar%%.*} $cmit <&3
				break
			fi
		done
	done

Variation using --numstat and a path filter to find the closest commit ignoring some files instead of an exact match left as an exercise to the reader.

Hope that helps, Jonathan

Previous: Michael SchubertNext: Michael Schubert
Message 5 of 6 in “Identify Commit ID from an Extracted Source Snapshot”
  1. James WalmsleyFeb 16, 2012
  2. Michael SchubertFeb 16, 2012
  3. Sam VilainFeb 16, 2012
  4. Michael SchubertFeb 16, 2012
  5. Jonathan NiederFeb 16, 2012
  6. Michael SchubertFeb 17, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.