views:

3036

answers:

12

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 will mess up the paths on all the other developer machines - they will be unhappy.

If I do delete the file from versioning, it will be deleted from the other developers machines - they will be unhappy.

I there f I choose to never commit the file, I always have a "dirty" checkout - I am unhappy.

Is a clean way to "unversion" a file from revision-control, that will result in no-one being unhappy?

edit: trying to clarify a bit: I have already commited the file to the repository and I want to only remove it from versioning - I specifically do not want it to be physically deleted from everyone doing a checkout. I initially wanted it to be ignored.

Answer: If I could accept a second answer, it would be this. It answers my question with respect to git - the accepted answer is about svn.

+2  A: 

If you accidentally 'add' a file in svn & you haven't committed it, you can revert that file & it will remove the add.

Glenn Slaven
+2  A: 

To remove a file already in source control:

git rm <filename>

and then

git commit -m ...

You should add every file you want to ignore to the .gitignore file. I additionally always check the .gitignore file to my repository, so if someone checks out the code on his machine, and the file gets generated again, he won't 'see' it as 'dirty'.

Of course if you already committed the file and someone else got your changes on another machine, you would have to alter every local repository to modify the history. At least that's a possible solution with git. I don't think svn would let you do that.

If the file is already on the master repository (git) or in the server (svn), I don't think there is a better solution than just deleting the file in another commit.

Sergio Acosta
A: 

For SVN you can revert files you haven't committed yet. In TortoiseSVN you just right click the file in the commit window and choose Revert...

On command line use svn revert [file]

Don't know about GIT since I've never used it.

Magnus Westin
A: 

As far as I know there is no easy way to remove an added file from versioning control in svn once it is committed.

You will have to save the file somewhere else and delete it from version control. Than copy the backup back again.

It's a version control system after all... ;)

FantaMango77
+3  A: 

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.

Greg Hewgill
A: 

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

paan
+3  A: 

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.

Kai
+4  A: 

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:

  1. Mark the file as deleted and commit.
  2. Perform an 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.

Trumpi
+2  A: 

To remove a file entirely from a git repository (Say you commited a file with a password in it, or accidently commited temporary files)

git filter-branch --index-filter 'git update-index --remove filename' HEAD

Then I think you have to commit, and push -f if it's in remote branches (remember it might annoy people if you start changing the repository's history.. and if they have pulled from you before, they could still have the file)

dbr
A: 

I there f I choose to never commit the file, I always have a "dirty" checkout - I am unhappy.

With regard to this particular point, you might want to .gitignore the file as other have suggested, or to use a scheme like the one described in this answer of mine.

Damien Diederen
+6  A: 

SVN version 1.5 supports removing/deleting a file from a repository with out losing the local file

taken from http://subversion.tigris.org/svn_1.5_releasenotes.html

New --keep-local option retains path after delete..

Delete (remove) now takes a --keep-local option to retain its targets locally, so paths will not be removed even if unmodified.

you can then use svn propedit with the svn:ignore property to make sure these locally stored files don't come up in future changes.
jorelli
+2  A: 

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>
wxs