81

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.

If 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.

asked Aug 26, 2008 at 10:20

15 Answers 15

89

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>
answered Jun 4, 2010 at 22:27

4 Comments

Will that delete everyone else's copy of the file when they pull changes?
I'm stuck with RabbitVCS and your command just work as a charm for me. Thank you! @wxs
@BenLessani-Sonassi - what if they have local changes? Merge after pull fails?
@BenLessani-Sonassi But then is there a way to unversion it for everyone without having it being deleted?
35

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.

answered Jun 30, 2009 at 21:59

7 Comments

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.
Does that prevent SVN from deleting everyone else's local copy also?
Answer: no it does not! Damn!
In TortoiseSVN this option is hidden in the "extended context menu": shift-right-click the file.
in my experience, that wouldn't keep the file in other developers' machines.
|
9

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

answered Aug 26, 2008 at 10:21

Comments

6

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.

answered Aug 26, 2008 at 10:47

1 Comment

You'll need to pass the --cached switch to rm like so git rm --cached <file> so that it's only removed from the index and not the file system.
4

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.

answered Aug 26, 2008 at 10:52

Comments

3

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.

answered Aug 26, 2008 at 10:26

Comments

3

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)

answered Aug 30, 2008 at 12:08

Comments

2

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.

answered Aug 26, 2008 at 10:24

Comments

1

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.

answered Aug 26, 2008 at 10:24

Comments

1

Two simple steps in SVN:
1. Add this directory in parent directory's svn:ignore property:

svn propedit svn:ignore . 

2. Remove directory:

svn rm mydir

3. Commit

Please note that when other developers do a svn update, that directory will not get deleted. SVN just unversions it instead.

answered Mar 21, 2012 at 5:36

Comments

0

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... ;)

answered Aug 26, 2008 at 10:25

Comments

0

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

answered Aug 26, 2008 at 10:27

Comments

0

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.

answered Aug 31, 2008 at 12:11

Comments

0

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
answered Mar 9, 2016 at 12:13

Comments

0

In Windows, if what you are looking for is copying the folder to another location and removing it from git, so that you don't see the icons anymore, you just delete the .git folder. The .git folder is hidden, so you have to go to Organize / Folder and Search Options, Display hidden Files option, under your main folder. It should unversion it.

answered Dec 6, 2016 at 17:31

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.