Two quick git tricks

A handy oneliner

To retrieve the contents of a file from a different branch without affecting your current git state:

git show `git rev-parse $BRANCH_NAME:$FILE_PATH`

Creating full git history from release tarballs

Given a set of tar-balls from a project whose version control is not exposed to the public:

toby-whites-macbook:python-memcached tow$ ls /Volumes/ftp.tummy.com/old-releases/*.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.2.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.2_tummy1.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.2_tummy2.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.2_tummy3.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.2_tummy4.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.2_tummy5.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.2_tummy6.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.31.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.32.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.33.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.34.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.36.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.37.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.38.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.39.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.40.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.41.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.42.tar.gz
/Volumes/ftp.tummy.com/old-releases/python-memcached-1.43.tar.gz

We can turn this into a git repository with full version history fairly easily:

PROJECT=python-memcached
mkdir $PROJECT
(
  cd $PROJECT
  git init
  git commit --allow-empty -m "Empty repo"
)
for i in $PROJECT*.tar.gz; do
  vntgz=${i#$PROJECT-}
  vn=${vntgz%%.tar.gz}
  echo $vn
  tar xzf $i
  mv $PROJECT/.git $PROJECT-$vn
  (
    cd $PROJECT-$vn
    find . -name '.git' -prune -o -exec git update-index --add --remove {} \;
    git commit -m $vn
  )
  mv $PROJECT-$vn/.git $PROJECT
done

For re-use, you might need to play around with some of the substring matching to get the right naming conventions for another project.

You don't get a useful Changelog, but now you can do git bisect tricks and the like.

Comments have been automatically disabled | digg this | reddit | del.icio.us