Mittwoch, 26. September 2012

I recently had to commit a large patch series to a largish project using SVN and edit all commit messages. This in order to preserver the original author attributions which would be lost if all committed by me against SVN. I used git-svn to do this, first I had to copy the branch and correctly rebase it as described here (I had the same problem with the floating branch so I applied to proposed solution in one of the comments):
git config --add svn-remote.newbranch.url https://svn/path_to_newbranch/
git config --add svn-remote.newbranch.fetch :refs/remotes/newbranch
git svn fetch newbranch 
git checkout -b local-newbranch -t newbranch
# determine last commit on trunk before branch (sha1_1)
# determine first commit on branch (sha1_2)
git diff-tree sha1_1 sha1_2 # make sure there is no diff
git rebase sha1_1
# Open .git/refs/remotes/newbranch and edit it to contain the full SHA1 of the new 
# commit (on the rebased newbranch) that corresponds to the old commit it's 
# currently pointing at. 
Then I could start to create the patch series, first creating all the files necessary and then using sed to rename the commit message (inserting the correct author name).
git format-patch master
grep "From:" * | cut -f 3 -d ":" | cut -f 2 -d " " | sort | uniq # show all authors
for file in `grep author1 00* | cut -f 1 -d ":"`; do
echo $file;
sed -i 's/\(Subject: \[PATCH [^ ]*\]\)/\1 [Feature] PATCH by author1:/' $file
done

git checkout master 
git branch -D featurebranch_rebased 
git checkout -b featurebranch_rebased 
for file in 00*; do
echo $file;
git am < $file
done
Thus I could attribute each patch to its owner in the SVN and then commit all patches using "git svn dcommit".