Subversion: prevent local modifications to one file from being committed?

Actually, a pre-commit script would do the job.

Write a pre-commit script that executes 'svnlook diff' and rejects the commit if there is a property named 'nocommit' being set in the changeset.

Then, in your working copy, you can just set a 'nocommit' property on any file that shouldn't be committed. Any subsequent commit will fail if any file has the 'nocommit' property. If you later do need to check in changes on the file, all you have to do is remove the 'nocommit' property from your working copy.


I understand the problem you're having; probably this "forbidden" file contains configuration settings and the like that are only relevant to your local build environment. I've not found any way directly to tell SVN just to ignore changes in a versioned file, but here's a workaround I've used in the past.

Assuming your file is called, say, "build.conf". Name the SVN versioned file something like build.conf.example. Then, in your Makefile or build script or whatever, you can automatically copy the build.conf.example to the real build.conf, which remains unversioned. Then you svn ignore build.conf and each developer can then make any local changes they need to it.

But "there must be a better way"...

Edit: Almost identical question here: SVN: Is there a way to mark a file as "do not commit"?


Create a changelist with that file in it, and then just pay no attention to the changelist. The file will sit there waiting to be committed, but your regular commits, which work on the default changelist, will never pick it up.

svn changelist mylocal file1

will create a changelist called mylocal and assign the file file1 to it.


There have been a few answers that can work:

  1. Create a pre-commit hook script that reject the commit when a specific property is being added. You can then add this property to files in the working copy to prevent commits.
  2. TortoiseSVN will exclude files in the special changelist "ignore-on-commit". However, this is not honored by the SVN command-line client.

CoverosGene suggested that the default commands such as svn commit operate on a default changelist, such that you can exclude a file if you assign it to another changelist, but I can't find any reference of that in the documentation, and in my testing this does not work.

Since there is no good solution for the SVN command-line client, I've opened an enhancement request here. The request suggests that the command-line client could also honor the "ignore-on-commit" changelist.

Update: This is now issue 2858 and there is a feature outline to handle it with an svn:hold property.

Tags:

Svn