Linux

git command collection

Contents

svn to git migration

1
2
git svn clone --stdlayout --no-metadata -A users.txt svn://example.com/repository/projectname
cd projectname

The command below is supposed to generate users.txt, but it doesn’t work for me.. maybe because perl is missing..
svn log ^/ --xml | grep -P "^<author" | sort -u | \ perl -pe 's/<author>(.*?)<\/author>/$1 = /' > users.txt

handle ignore file

1
git svn show-ignore -i trunk > .gitignore

set remote git

1
git remote add origin git@git.example.com:group/projectname.git

handle tags

1
git for-each-ref refs/remotes/tags | cut -d / -f 4- | grep -v @ | while read tagname; do git tag "$tagname" "tags/$tagname"; git branch -r -d "tags/$tagname"; done

handle branches

1
git for-each-ref refs/remotes | cut -d / -f 3- | grep -v @ | while read branchname; do git branch "$branchname" "refs/remotes/$branchname"; git branch -r -d "$branchname"; done

push

1
2
git push origin --all
git push origin --tags

revert local commit

1
git reset —hard remotes/origin/HEAD

backup

1
sudo gitlab-rake gitlab:backup:create

restore (restores the most recent backup)

1
sudo gitlab-rake gitlab:backup:restore

restore OPTION (I guess it restores to the timestamp specified below.. haven’t tried it..)
BACKUP=timestamp_of_backup (required if more than one backup exists)