There's a good book for git called Pro Git. There's a section on how to migrate from a custom structure as well. (See Custom Importer). It's a little bit harder, but if you have a lot of history then that would be the best way.
The other way is to do:
# initialize a new repository
git init .
touch .gitignore
git add .
git commit -m "initial commit"
# copy all the files to working directory
cp -R backup_v01/* .
# stage all the files
git add .
# make the first commit
git commit -m "v0.1 from backup"
# remove all files
git rm -r *
# copy all the files to working directory
cp -R backup_v02/* .
git add .
git commit -m "v0.2 from backup"
This can be optimized but this script can easily be understood. You need to remove all old files from the repository before updating the contents because otherwise you would have some old deleted files hanging around.
Of course the whole thing can be made into a script (repo.sh):
#!/bin/bash
REPODIR=$1
# initialize a new repository
git init $REPODIR
cd $REPODIR
touch .gitignore
git add .
git commit -m "initial commit"
while read DIR
do
# remove all files
git rm -r *
# copy all the files to working directory
cd ..
cp -R $DIR/* $REPODIR/.
# go back to repo dir
cd $REPODIR
# stage all the files
git add .
# make the first commit
git commit -m "$DIR from backup"
done
The folder switching is necessary to make it work with relative paths.
You use it by sending all the folder paths to the script and specifying the repository directory (it must not exist):
# let's say all the backups are in this folder
# and there are no other folders
# test whether everything is in correct order
ls -d */ | sort
# verify that there is no repository directory
rm -rf REPO_DIR
# pipe the folder listing to the script
ls -d */ | sort | repo.sh REPO_DIR