Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subversion: Add revision data to code file on commit

Tags:

Is there an easy way to, on commit of a file, automatically insert information into the code file itself (like author, commit comment, commit date, etc)? I would want this information appended to a block at the top of each committed file. Essentially the entire revision history should be documented in each code file...

I see there is a way to use subversion properties to achieve something similar, but I don't see how to get the actual commit comment into the file, and also I don't see how to keep a running log that has the entire revision history as opposed to just the last commit information.

I don't personally think this is a good idea as the code file should just have code in it, but unfortunately this is a requirement for my current project.

like image 694
Mike Gates Avatar asked Jan 05 '10 20:01

Mike Gates


People also ask

How do I commit changes in svn?

Select any file and/or folders you want to commit, then TortoiseSVN → Commit.... The commit dialog will show you every changed file, including added, deleted and unversioned files. If you don't want a changed file to be committed, just uncheck that file.

What is difference between commit and update in svn?

Commit uploads your changes on the CVS / SVN server, and Update overwrites the files on your localhost with the ones on the server.

How does svn revision number work?

Each time the repository accepts a commit, this creates a new state of the filesystem tree, called a revision. Each revision is assigned a unique natural number, one greater than the number assigned to the previous revision.

How do I edit a TortoiseSVN file?

Click on the new working copy and right click to select the repository browser (TortoiseSVN -> Repo-browser) Right click the file of choice in the repository browser and select "Update item to revision"


1 Answers

Subversion supports various keywords like $Id$, $Author$, $Revision$ and so on. To use those you need to set the svn:keywords property accordingly. However, you can't insert the commit comment like $Log$ does. See the subversion FAQ for the reasons about this, and I can only agree with the reasons given there. Putting the commit comments into the file is simply broken by design, and any such comment is wrong the moment you can't check it against the repository.

Other version control systems also don't support this, and most of them with a similar reasoning (for example, git).

Please don't argue with something like that being a "requirement for the project". If released code has to include a change history you can add this history when creating the release with some helper script rather easily. At least, subversion simply doesn't support it. And I would strongly discourage trying to achive this with a pre-commit hook. Commit hooks should never change the data that gets committed.

like image 123
bluebrother Avatar answered Sep 20 '22 09:09

bluebrother