I have a Subversion working copy where I made some local modifications to one file. The modifications are only relevant to me, I do not want to commit them. (The version in
For the last several years I have been using a simple solution which achieves exactly what you are looking for. It is called the NOCOMMIT
keyword.
What I do is that I have a pre-commit hook in my SVN repository which checks to see whether any file contains the string NOCOMMIT
, and if so, it fails the commit.
So, when a programmer makes a modification that should not be committed, (say, they changed the project-wide database connection string from the company-wide test server to their own local test server, or they added diagnostic debug statements that are going to be spamming the log with thousands of lines per second,) they append a //NOCOMMIT
comment to it, and they do not have to worry about accidentally committing it. When the time comes to commit, they are prevented, so they are forced to either:
NOCOMMIT
and remove any occurrences of it, thus hopefully fixing the code that they had attached it to.Personally, I find the NOCOMMIT
keyword so useful that I use it even when working on pet projects of mine, where obviously, I am the only programmer in the team.
If you are using windows, you can paste the following text into file called pre-commit.bat
in the hooks
folder of your SVN repository.
:: Stops commits that contain the NOCOMMIT keyword.
setlocal
set REPOS=%1
set TXN=%2
SVNLook diff %REPOS% -t %TXN% | findstr /I /M /L NOCOMMIT > nul
if %errorlevel% gtr 0 (
exit 0
) else (
echo Your commit has been blocked because it contains the keyword NOCOMMIT. 1>&2
exit 1
)
On Unix systems, something like the following should do the trick, though please note that I have not tested it.
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/local/bin/svnlook
$SVNLOOK diff -t "$TXN" "$REPOS" | grep -i "NOCOMMIT" > /dev/null && { echo "Your commit has been blocked because it contains the keyword NOCOMMIT." 1>&2; exit 1; }
There have been a few answers that can work:
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.
From my experience: don`t put that file under version control and use svn:ignore on it.
It’s a little hard at the beginning, since you cannot ignore a file that is allready under version control, and you cannot remove a file from version control without removing it from hard drive (and from every working copy on next update...). But when you finally manage to set up the repo correctly, it works like charm. Don’t forget to add a generic-template in place of your original config file (so that everyone knows about new config variables, and so on).
For new repo:
mkdir config
svn add config
svn propset svn:ignore '*.conf' config
For existing repo: be sure, to have a backup of your config in every working copy, then remove (svn del) config from the repo, commit (please note: the file will be deleted in every working copy on next update! you have to have a backup) and then restore the file and set the ignore property.
Another way is a lock. It guarantees that noone commits the file, but it will result in an error on every commit. not very nice.
And the third way - changesets, a new feature in SVN 1.5 clients. This is neat, but it’s only related to one working copy, not to a repository globally. And you have to set them up manually, add every new file — it’s hard to maintain.
Lock certainly isn't what you want, and I don't think any of the built in features will do it for you.
Depending on which environment you are working in, I'd write a script that:
Something along the lines of:
svn status | grep ^M | grep -v exclude.c | awk -F' ' '{print $2}' | xargs svn ci -m "I'm committing something"
Or if the list of files is really static, just fix the list!
You can use a pre-commit hook.
In the hook use svnlook author
to see if you are the one committing the changes. If so, use svnlook changed
to see if you are changing one of the forbidden files.
Add all files to a changelist and then remove the files you do not want to commit. Finally commit the changelist as shown below:
$ svn status
M file01
M ...
M file100
M file_not_ready_for_commit
// This will add all working copy files, can be adjusted to add only relevant files
$ svn changelist mychangelist -R .
// Remove the nascent one(s)
$ svn changelist mychangelist --remove file_not_ready_for_commit
// Commit only the files in the changelist
$ svn commit --changelist mychangelist
Source of above information is this blog which also has a link to http://svnbook.red-bean.com for further details. All credits to the author of the blog.