It happens to me all the time. I accidentally version a file, I do not want to be versioned (i.e. developer/machine specific config-files).
If I commit this file, I
In Git, in order to delete it from the tree, but NOT from the working directory, which I think is what you want, you can use the --cached flag, that is:
git rm --cached <filename>
You can exclude files from subversion with the global-ignore setting
http://svnbook.red-bean.com/en/1.1/ch07.html#svn-ch-7-sect-1.3.2
check out the documentation for details
It sounds like you have already added and committed the file to subversion (I assume that you are using Subversion). If that is the case, then there are only two ways to remove that file:
svnadmin dump
, filter out the revision where you accidentally committed the file and perform an svnadmin load
.Trust me, you don't really want to do number 2. It will invalidate all working copies of the repository. The best is to do number 1, mark the file as ignored and apologise.
Look up svn:ignore and .gitignore - these features allow you to have extra files in your checkout that are ignored by your RCS (when doing a "status" operation or whatever).
For machine-specific config files, a good option is to check in a file named with an extra ".sample" extension, ie. config.xml.sample
. Individual developers would make a copy of this file in config.xml
and tweak it for their system. With svn:ignore or .gitignore you can ensure that the unversioned config.xml
file doesn't show up as dirty all the time.
In response to your edit: If you remove the file from the repository now, then your developers will get a conflict next time they do an update (assuming they have all changed the file for their system). They won't lose their local changes, they will be recoverable from somewhere. If they happen not to have made any local changes, then their config file will vanish but they can just re-get the previous one out of source control and use that.
You can unversion all files in current directory with this command. The sed
bit reverses the order so svn can process it:
find . | sed '1!G;h;$!d'| awk '{print "svn rm --keep-local " $1}'
As already stated in other answers, single file is unversioned with this:
svn rm --keep-local yourFileNameXXX
Without having tried it...
In git, if your changes haven't been propagated to another repository, you should be able to git rm
the affected file(s), git rebase --interactive
to reorder the deletion commit to be just after the commit in which you accidentally added the offending files, and then squash those two commits together.
Of course, this won't help if someone else has pulled your changes.