Reputation: 4039
I have a repository ("apple") in Subversion v1.8 format. It contains two projects ("apple" and "orange"). I need to migrate this to Git, and completely erase the "orange" project, so that there is no history, no references, no evidence that it ever existed.
This is as far as I've got, but there are still references to the removed files (and possibly the actual file data, for all I know)...
#!/bin/bash
# installations
# sudo apt-get install subversion git git-svn
# cleanup
rm -rf apple* orange*
# current directory (because svn checkout needs absolute path)
D=`pwd`
# create svn repository and check it out
svnadmin create apple-svn-repo
svn checkout file:///$D/apple-svn-repo/ apple-svn
# commit trunk
cd apple-svn
mkdir trunk
svn add trunk
svn commit -m "trunk"
# commit apple dir
mkdir trunk/apple
echo "apple file" > trunk/apple/applefile.txt
svn add trunk/apple
svn commit -m "apple file"
# commit orange dir
mkdir trunk/orange
echo "orange file" > trunk/orange/orangefile.txt
svn add trunk/orange
svn commit -m "orange file"
# check log
svn update
svn log
# back to original dir (can also cd ..)
cd $D
# clone from SVN to GIT
git svn clone -s file:///$D/apple-svn-repo/ apple-git
cd apple-git
# remove the remote svn config section
git config --remove-section svn-remote.svn
# remove all SVN logs, refs and other data
rm -rf .git/svn .git/{logs/,}refs/remotes/{git-,}svn/
# garbage collect to tidy up
git gc
# still have unstaged changes... need to commit locally and reset head
git add .
git reset --hard
# remove "orange"
git filter-branch --index-filter "git rm -r --cached --ignore-unmatch orange" --prune-empty
# mark backup as expired
git reflog expire --expire=now --all
# remove 'git-svn-id: svn://' messages from untitled commits
git filter-branch -f --msg-filter 'sed "s/git-svn.*$//g"' -- --all
# garbage collect to remove expired backup and unused remotes
git gc --aggressive --prune=now
# moment of truth
git log
git rev-list --all --objects
Which produces the output:
8f746d2cf2f6dcf77135fc4ae6e7b1263a6a070a
812010c9a2ed14892420862718408c33ab948a3f
406ac30ad5770f1c3eec5b1e9bb2b7321a2dc0cb
567c85d300426a6f02e1a38a87980a28cbba27fa
69705a92944e1cc1ffafee747df317ef4d0a94f7
55f51f76bbc51ca206f6b62d8d51797455ff566c apple
358f29228e6394ad06ccbf46eaaa3f5104514f4c apple/applefile.txt
d4efd18a7e55206f8f8531cbd4b589ed0e47d5c5 orange
ba2d1295e8d99acf9f64f072b951dc1ebf516cd2 orange/orangefile.txt
a167088b4e4957ff6e78c227e8092139408c81f8
So how can I completely erase "orange" and its file?
EDIT: Someone posted an answer, and deleted their post while I was trying it out. So I don't know who you are, but thankyou. The actual working solution is this:
#!/bin/bash
# installations
# sudo apt-get install subversion git git-svn
# cleanup
rm -rf apple* orange*
# current directory (because svn checkout needs absolute path)
D=`pwd`
# create svn repository and check it out
svnadmin create apple-svn-repo
svn checkout file:///$D/apple-svn-repo/ apple-svn
# commit trunk
cd apple-svn
mkdir trunk
svn add trunk
svn commit -m "trunk"
# commit apple dir
mkdir trunk/apple
echo "apple file" > trunk/apple/applefile.txt
svn add trunk/apple
svn commit -m "apple file"
# commit orange dir
mkdir trunk/orange
echo "orange file" > trunk/orange/orangefile.txt
svn add trunk/orange
svn commit -m "orange file"
# check log
svn update
svn log
# back to original dir (can also cd ..)
cd $D
# clone from SVN to GIT
git svn clone -s file:///$D/apple-svn-repo/ apple-git
cd apple-git
# remove "orange"
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch orange/* orange" --prune-empty -- --all
rm -rf .git/refs/original/refs/
rm -rf .git/logs/refs/
git reset --hard
git reflog expire --expire=now --all
git gc --aggressive --prune=now
# moment of truth
git log
git rev-list --all --objects
Upvotes: 2
Views: 304
Reputation: 411
this is because you still have a reference on orange files due to remote/trunk reference on your svn repository. After cleaning you can perform a clone to be sure that you no more have pending references
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch orange/* orange" --prune-empty -- --all
rm -rf .git/refs/original/refs/
rm -rf .git/logs/refs/
git reset --hard
git reflog expire --expire=now --all
git gc --aggressive --prune=now
cd ..
git clone apple-git apple-git.clean
cd apple-git.clean
git remote rm origin
git rev-list --all --objects
you should obtain
f3b260205c3b6a1ea9e64bab2554bd232f4c7aca
65a5013381de325056828079834dcf9450318c9e
31348b45188be3660383b6dc4e80971c1ef509d3 apple
358f29228e6394ad06ccbf46eaaa3f5104514f4c apple/applefile.txt
Upvotes: 2