Version Control System tips and tricks
How to choose VCS?
Since most projects are based on Maven, we are limited to using products supported by Maven. See SCM Overview .
Comparison between Bazaar, CVS, Git, Mercurial, Subversion might also be helpful.
Quickly revert a commit
- Find the revision number of the commit you want to revert.
- svn log --limit 5
- Merge in the negation of the change set from that commit. To revert revision 7:
- svn merge -c -7 .
Use Subversion post-commit hook to send out email
Why?
- "Cheap communication" ,i.e. you absorb a lot of information with minimum effort
- Covers some aspects of code and change review and control, since controversial commits are more easily detectable.
- Train developers in VCS best practices. E.g. how to structure your commits and how detailed your commit messages should be.
The only disadvantage of implementing this tactic is increased email sending. This potential challenge is solved by sending email to an email list and setting up sane subjects, as this will allow easy filtering of the email.
How?
- Make sure /usr/sbin/sendmail works.
- Copy post-commit template
cp ${repoPath}/hooks/post-commit.tmpl ${repoPath}/hooks/post-commit
commitScript=`find / -name commit-email.pl | grep hook-scripts`
cp ${commitScript} ${repoPath}/hooks/commit-email.pl
@@ -47,8 +47,8 @@
# You should define exactly one of these two configuration variables,
# leaving the other commented out, to select which method of sending
# email should be used.
-#$sendmail = "/usr/sbin/sendmail";
-$smtp_server = "127.0.0.1";
+$sendmail = "/usr/sbin/sendmail";
+#$smtp_server = "127.0.0.1";
#!/bin/sh
REPOS="$1"
REV="$2"
/path/to/repo/hooks/commit-email.pl "$REPOS" "$REV" mailing-list@example.org specific.user1@example.org specific.user2@example.org
chmod a+x ${repoPath}/hooks/{commit-email.pl,post-commit}
Resources
- Quick pragmatic setup
- A more extensive how-to
- Version Control with Subversion - Hook scripts
- Contributed hook scripts at subversion.tigris.org
Note that the perl script in SVN has been deprecated in favor of the more powerful python mailer.py.
There is also an even more powerful tool available at http://opensource.perlig.de/svnmailer/ - however, it requires some python and python-svn bindings and seems a bit tricky to set up. If you have Ruby installed, the easiest thing to follow this recipe: http://blog.hungrymachine.com/2007/11/05/pretty-svn-commit-emails/
Avoid IDE specific files and such in the VCS repository
Why?
IDE specific files are seldom identical between environments (even though the same IDE is used) and change quite frequently.
How
Set up the repository to ignore these files. The following filter is a good starting point.
global-ignores = *.iml *.iws *.ipr target test-output activemq-data .classpath .project .settings *.o *.lo *.la ## ..rej *.rej .~ ~ .# .DS_Store
This can be done on the root folder of the project or globally for your client.
Client:
vim /home/erik/.subversion/config