Reputation: 11
I'm just converting old repositories (SVN & VSS) to Git and in these is a lot of erroneous information I want to correct. I have erroneous authors / committers standing in some time blocks because same users have worked with 2 logins and here the login of a colleague was used.
I used git filter with the --after option to find the corresponding commit IDs and now have a text file in which the commit IDs have to be stored line by line, where only the author has to be replaced.
I have now tried with
git commit --amend --author="<my new author>" --no-edit <commit hash>
to replace the respective commits now, but I always get a message here
did not match any file(s) known to git
As I understood it, I first have to check out the commit, then change it, and then rebase it. Only then would all filtered commit IDs change.
I need a solution where I go through every line of the text file and then set the author for each of the IDs and rebase at the end:
for i in $(cat /tmp/commitids.txt); do
<I dont know the correct git command to replace the author of the commit in $1>
done;
<I don't know the correct rebase command for all the changes>
Upvotes: 0
Views: 91
Reputation: 60275
You want filter-branch, it handles the id rewrites for you, you just supply the content and metadata changes. In your case, assuming your commitids file is tab-separated hash code, author name, author email, it's going to be something very close to (keyboard-to-textbox warning)
git filter-branch --setup '
declare -A authors; while read id auth; do authors[$id]=$auth; done <commitids
' --env-filter '
[[ -v authors[$GIT_COMMIT] ]] && {
GIT_AUTHOR_NAME=${authors[$GIT_COMMIT]}
GIT_AUTHOR_EMAIL=${authors[$GIT_COMMIT]}
GIT_AUTHOR_NAME=${GIT_AUTHOR_NAME%$'\t'*}
GIT_AUTHOR_EMAIL=${GIT_AUTHOR_EMAIL#*$'\t'}
}
'
Upvotes: 1