如何从 SVN 存储库中删除文件/文件夹并添加到忽略列表 [英] How to remove a file/folder from a SVN repository and add to the ignore list

查看:55
本文介绍了如何从 SVN 存储库中删除文件/文件夹并添加到忽略列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我来说,这听起来像是在手册中查找的问题,但我找不到.假设我们有一个包含文件和目录的存储库,其中不应受版本控制,而应在忽略列表中(例如 Eclipse 文件 .settings.project>,生成的文档文件 - 本来就不应该添加和提交的内容).从存储库中删除这些文件并将它们直接移到忽略列表中的最佳方法是什么?

This sounds like a look-up-in-the-manual question to me, but I can't find it. Suppose we have a repository with files and directories in it that shouldn't be under version control but rather should be on the ignore list (such as Eclipse files .settings, .project, generated documentation files - things that should never have been added and committed in the first place). What is the best way of deleting these files from the repository and moving them straight onto the ignore list?

更新:下面接受的答案详细说明了设置本地 subversion 存储库以避免上述问题的好方法.但是,如果您仍然必须解决这个问题,似乎您必须进行一些手动操作才能将文件/文件夹从存储库中取出并放到忽略列表中.

Update: The accepted answer below details a good way of setting up your local subversion repositories to avoid the problem described above. However, if you still have to solve this, it seems that you have to do some manual fiddling to get files/folders out of the repository and onto the ignore list.

例如,对于 .settings 文件夹,首先将其添加到全局忽略列表中,然后运行以下命令:

For instance, for the .settings folder, first add this to the global ignores list and then run the following command:

$REMOVE=".settings"
cp -r "$REMOVE" /tmp/ && \
svn rm "$REMOVE" && \
svn commit -m "Moving to ignore list" "$REMOVE" && \ 
mv "/tmp/$REMOVE" .

这会将文件/文件夹复制到一个临时位置,然后将其从 SVN 中删除并提交删除 - 最后将文件/文件夹复制回来,但由于它现在位于忽略列表中,它将被 SVN 忽略.

This copies the file/folder to a temporary location and then removes it from SVN and commits the remove - finally the file/folder is copied back, but as it is now on the ignore list it will be ignored by SVN.

推荐答案

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.

这篇关于如何从 SVN 存储库中删除文件/文件夹并添加到忽略列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆