且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从 SVN 存储库中删除文件/文件夹并添加到忽略列表

更新时间:2023-09-26 09:48:58

subversion 有两种方式,一种是特定于用户的,另一种实际上是在存储库中维护,因此影响到每个人.

There are two ways with subversion, one is specific to the user and the other is actually maintained in the repository, and therefore affects everyone.

对于全局忽略文件的列表(每个用户/机器独享),您需要编辑 subversion 配置文件并更改 miscellany 中的 global-ignores 指令> 部分.配置文件记录在案,语法非常简单.例如:

For a list of globally ignored files (exclusive to each user/machine), you need to edit the subversion config file and alter the global-ignores directive in the miscellany section. The config file is documented and the syntax is very simple. For example:

global-ignores = *.o

在 UNIX 系统上,配置文件位于 ~/.subversion/config.在 Windows 系统上,配置文件位于 %APPDATA%\Subversion\configHKCU\Software\Tigris.org\Subversion\Config 下的注册表中.

On a UNIX system, the config file is found at ~/.subversion/config. On a Windows system, the config file is found at %APPDATA%\Subversion\config or in the registry under HKCU\Software\Tigris.org\Subversion\Config.

一旦您进行了设置,您将永远不会意外地将这些文件添加到您的存储库中,这些文件也不会在您的 svn stat 命令中显示为 ?.如果您的存储库已经有这些文件,那么将它们保持原样可能不会有什么坏处,但是将来对文件的更改和修改将被忽略.

Once you set this up, you will never accidently add these files to your repository, nor will the files show up as ? in your svn stat commands. If your repository already has these files, it probably won't hurt to leave them there as they are, but changes and modifications to the files will be ignored in the future.

要在每个项目的基础上进行设置(这将影响检查项目的任何人),您需要将 svn:ignore 属性添加到可能存储文件的项目目录中.例如,要从项目的顶层排除名为 build 的目录,您可以执行以下操作:

To set this up on a per-project basis (which will affect anyone checking out the project), you would add the svn:ignore property to the project directories where files are likely to be stored. For example, to exclude a directory named build from the top-level of your project, you would do something like this:

svn propset svn:ignore 'build' .
svn commit -m 'project ignores build directory' .

从现在开始,你的项目中的 build 目录将被 subversion 忽略.有关更多信息,请参阅 http://subversion.tigris.org/ 上的文档或发出 svn help 命令以获取更多信息.

From now on, the build directory in your project will be ignored by subversion. For more on this, see the documentation at http://subversion.tigris.org/ or issue the svn help command for more information.

根据评论添加了更多内容......不知道我怎么错过了原始问题的那部分!!对不起:)

不幸的是,从存储库中删除您现在想要忽略的文件是一个手动过程,但是,如果您确切知道它们是哪些文件,您可以编写一个小脚本,让遇到此问题的人可以运行(将来,svn:ignore 属性将使他们不必重复它,并且它的优点是能够在需要时轻松修改).

Unfortunately, removing the files that you now want ignored from the repository is a manual process, although, if you know exactly which files they are, you could write a little script that people having this problem could run (in the future, the svn:ignore property would keep them from ever having to repeat it, and it has the advantage of being able to be easily modified when the need arises).

要从存储库中删除不需要的文件,但保留本地文件,请执行以下步骤:

To remove the files that you don't want from the repository, but keep the local files around, follow these steps:

  1. 创建您的 global-ignores 条目或将 svn:ignore 属性添加到您的存储库并提交.
  2. 对于要从存储库中删除的每个文件,发出以下命令:svn rm --keep-local filename
  3. 为每个文件发出 svn rm 命令后,提交您的工作副本.
  1. Create either your global-ignores entry or add the svn:ignore property to your repository and commit.
  2. For each file that you want to remove from the repository, issue this command: svn rm --keep-local filename
  3. Once you've issued the svn rm command for each file, commit your working copy.

因为如果人们没有更新他们的配置文件,这可能会产生从人们当前工作副本中删除文件的副作用,我强烈建议使用存储库目录上的 svn:ignore 属性.这样,当人们更新时,他们不会意外删除文件,因为他们还没有修改他们的 global-ignores 参数.

Because this may have the side-effect of deleting files from people's current working copies if they haven't updated their config files, I highly recommend using the svn:ignore property on the repository directories. That way, when people update, they won't unexpectedly have files deleted because they haven't modified their global-ignores parameter yet.