Changing the Author of a Single Tag in git
My team recently moved from Subversion to git, a migration we have been considering and planning for the past several months. We tripped over many stumbling blocks on our way; I intend to write about many of those in the coming months.
The day after the migration, we found ourselves needing to create a support branch1 for one of our components. We do this by branching from a tag and naming it as such:
That should just work. However, we have quite a few pre-commit hooks in place to keep everybody working with the same set of standards. One of these requires that you're pushing only your own changes, and that your author info matches. In SVN, our tags were all created by an internal service account running our releases (srv-clubuilder), so the release point and the tag created from it were both done under that user. Well, that user doesn't exist any more, and certainly I'm not him. When my team tried to do the above, we saw this lovely error:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Yes. Those are teddy bears.
I tried a few things like creating an empty commit as myself and pushing that, but it didn't matter—that wasn't the commit it was complaining about. I tried amending that commit, but since I hadn't changed anything, there was nothing to amend. In order to modify the branch, I needed to change the author of the tag itself. Most search results directed me to use git-filter-branch, and while I'm comfortable re-writing my repositories history (we did just do that, more or less, during the migration), I didn't want to cause any additional confusion.
Git, however, is pretty darn powerful. Some teams, after they have been using git a while, move from a traditional lightweight tag to a richer annotated tag, which might contain additional author information or be cryptographically signed by the author. We're sticking with lightweight tags for now, but the migration process for historical tags was similar to what I wanted to do. In the end, I was able to re-write only the tag and successfully create my branch:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
The result of this was exactly as I expected. When I look at the commit in the history, I now see that I am the author of this tag:
And now I'm in business.
We’re using git-flow as a branching model, but have the need to keep some releases around long-term for production support of integrations which cannot upgrade. This varies from a traditional concept of a hotfix in that we also need to be able to port features back to this release stream.↩