Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change author of old commits in Subversion

Tags:

svn

I have a user that has, up until today, been called foo.bar. Now that user will be known as fb instead from here on. But I would like to update all the old commits to reflect this username instead of the old one for statistical reasons etc. How can this be done?

I know about the syntax

svn propset --revprop -r revision_number svn:author your_username 

But that would require a lot of manual labor. Is there an existing function or script that just takes the name to replace and the name to replace it with?

Update:

Here is a small script I made to handle this since I will be doing this on a lot of repos for a lot of users :) Just run it in the checked out repository folder of your choice. Note that error handling is at a minimum in the script.

https://github.com/inquam/svn-rename-author

like image 1000
inquam Avatar asked Feb 13 '12 15:02

inquam


People also ask

Can I change commit message in svn?

By default, the log message property (svn:log) cannot be edited once it is committed. That is because changes to revision properties (of which svn:log is one) cause the property's previous value to be permanently discarded, and Subversion tries to prevent you from doing this accidentally.

How do I change the author of a commit in bitbucket?

Open the Commit Dialog locally, select "Amend", check "Set author" and then commit and force push. If the commit is older, you need to rebase. Checkout the branch the commit is on and then right click on the commit before the one you want to change in the log dialog and select "Rebase onto".


1 Answers

You can build a command to get the revisions in the log which old_username has committed with:

svn log | grep "^r[0-9]* | old_username |" | cut -c 2- | awk '{print $1}' 

This command gets the logs, searches for lines that appear at the start of each revision, drops the first character (i.e. the r) from those lines and then takes the first remaining part of the line, which is the revision.

You can use this information in a variety of ways. In bash you could make it produce the sequence of svn propset commands with:

for f in `svn log | grep "^r[0-9]* | old_username |" | cut -c 2- | awk '{print $1}'` do svn propset --revprop -r $f svn:author your_username done 

which iterates over the values created by the first expression (now in backquotes) and uses those values for your svn propset command, replacing the $f with the appropriate revision value.

like image 168
borrible Avatar answered Sep 24 '22 15:09

borrible