SVN: Ignoring an already committed file

2020-02-08 11:27发布

I have a settings file that is under version control using subversion. Everybody has their own copy of this file, and I need this not to be ever committed. However, like I said, there is already a copy under version control. My question is: how do I remove this file from version control without deleting everyone's file, then add it to the ignore list so it won't be committed? I'm using linux command line svn.

6条回答
ゆ 、 Hurt°
2楼-- · 2020-02-08 12:12

After you delete the file, your users will have to recover the file from the repository using svn export.

$ svn export -r x path ./

Where x is a revision where the file existed before it was deleted, path is the full path to the file, and ./ is where the file will be placed.

See svn help export for more information.

查看更多
We Are One
3楼-- · 2020-02-08 12:19

I have a similar issue. In my case it's an auto-generated user settings file (visual studio) that was accidentally checked in very early in the project. While just deleting it might work, it seems more correct to have it removed from the history, as it was never supposed to be in there in the first place.

I came across this, which might be a new feature since this question was originally posted 7.5 years ago:

https://stackoverflow.com/a/6025750/779130

Seems like an idea would be to:

1) create a dump of the project.
2) filter the dump using `svndumpfilter` to exclude the unwanted file(s).
3) load the dump as a new project.

This might be the only way to completely get rid of the file. In most cases the "delete and ignore" approach might be good enough.

查看更多
孤傲高冷的网名
4楼-- · 2020-02-08 12:27

Make a clean checkout, svn delete the file and add the ignore. Then commit this. Everyone else will have to take care (once) that their local copy isn't deleted on the next svn update, but after that, the local file would stay undisturbed and ignored by SVN.

查看更多
5楼-- · 2020-02-08 12:28

If you remove the file from version control, how does a developer new to the project (or the one who accidentally deleted his local copy) get it after initial checkout? What if there are additions to the settings file?

I would suggest the following: Keep a default settings file (with no passwords, hostnames, connection strings, etc.) in SVN, name it something like settings.dist, and let the code work with a copy of this, named settings. Every developer has to make this copy once, and can then work with her personalized settings. If there are additions, add them to settings.dist – everyone else will get them with a update and can merge then into her personalized copy.

查看更多
forever°为你锁心
6楼-- · 2020-02-08 12:30

simply define a file containing settings that will override the default ones. This file is not checked into Subversion and each developer is responsible for maintaining this file according to their environments.

In an Ant-based world, you would have the files:

settings.properties
settings-local.properties (ignored for Subversion)

and in your build.xml file

<property file="settings-local.properties"/>
<property file="settings.properties"/>

For those who couldn't connect the dots:

  1. modify the build.xml file like proposed
  2. set the setting-local.properties as ignored
  3. in an init target of your build, copy the settings.properties to settings-local.properties
  4. wait a couple of days until everyone had the chance to run this target
  5. delete the setting.properties from Subversion

Voila, every developer has its own setting-local.properties and everything was done automatically (and no developer lost his or her settings, which happens if you brutally delete the file from Suvbersion and there is no "Everyone else will have to take care...")

查看更多
\"骚年 ilove
7楼-- · 2020-02-08 12:31

[[ I'm new to subversion, so maybe this doesn't make sense. marking this as wiki -- if you know the right answer, please APPEND in the later section ]]

Couldn't you have a custom set of checkout steps so each user gets a different settings folder?

$ svn checkout http://example.com/project  project
..
$ dir project
original_settings\     folder1\     folder2\ 
$ svn checkout http://example.com/project/aaron_settings project\settings
..
$ dir project
original_settings\     folder1\     folder2\    settings\

Or for new users

$ svn import project\settings  http://example.com/project/aaron_settings

What I'm getting at is you want each user to have a custom view of the repository. In other version control systems, you could set up a custom listing of which projects you were using and which you weren't and which you put in odd places.

Does this work in subversion? The above code looks really risky, but maybe i'm doing it wrong.

WIKI:

(nothing yet)

查看更多
登录 后发表回答