简体   繁体   English

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

[英]How to remove a file/folder from a SVN repository and add to the ignore list

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).假设我们有一个包含文件和目录的存储库,其中的文件和目录不应受版本控制,而应位于忽略列表中(例如 Eclipse 文件.settings.project 、生成的文档文件 - 不应该添加和首先提交)。 What is the best way of deleting these files from the repository and moving them straight onto the ignore list?从存储库中删除这些文件并将它们直接移到忽略列表中的最佳方法是什么?

Update: The accepted answer below details a good way of setting up your local subversion repositories to avoid the problem described above.更新:下面接受的答案详细说明了设置本地 subversion 存储库以避免上述问题的好方法。 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.但是,如果您仍然必须解决这个问题,似乎您必须进行一些手动操作才能将文件/文件夹从存储库中取出并放到忽略列表中。

For instance, for the .settings folder, first add this to the global ignores list and then run the following command:例如,对于.settings文件夹,首先将其添加到全局忽略列表中,然后运行以下命令:

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

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

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 有两种方式,一种是特定于用户的,另一种实际上是在存储库中维护,因此影响到每个人。

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.对于全局忽略的文件列表(每个用户/机器专有),您需要编辑 subversion 配置文件并更改miscellany部分中的global-ignores指令。 The config file is documented and the syntax is very simple.配置文件记录在案,语法非常简单。 For example:例如:

global-ignores = *.o

On a UNIX system, the config file is found at ~/.subversion/config .在 UNIX 系统上,配置文件位于~/.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 .在 Windows 系统上,配置文件位于%APPDATA%\\Subversion\\config或注册表中HKCU\\Software\\Tigris.org\\Subversion\\Config

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.在您的svn stat命令中。 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.如果您的存储库已经有这些文件,将它们保留原样可能不会有什么坏处,但是将来对文件的更改和修改将被忽略。

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.要在每个项目的基础上进行设置(这将影响签出项目的任何人),您需要将 svn:ignore 属性添加到可能存储文件的项目目录中。 For example, to exclude a directory named build from the top-level of your project, you would do something like this:例如,要从项目的顶层排除名为build的目录,您可以执行以下操作:

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

From now on, the build directory in your project will be ignored by subversion.从现在开始,你的项目中的 build 目录将被 subversion 忽略。 For more on this, see the documentation at http://subversion.tigris.org/ or issue the svn help command for more information.有关更多信息,请参阅http://subversion.tigris.org/ 上的文档或发出svn help命令以获取更多信息。

EDIT: Added more based on comment... dunno how I missed that part of the original question!!编辑:根据评论添加了更多内容......不知道我怎么错过了原始问题的那部分!! Sorry :)对不起 :)

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

To remove the files that you don't want from the repository, but keep the local files around, follow these steps:要从存储库中删除不需要的文件,但保留本地文件,请执行以下步骤:

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

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.因为如果人们没有更新他们的配置文件,这可能会从人们当前的工作副本中删除文件,所以我强烈建议在存储库目录中使用 svn:ignore 属性。 That way, when people update, they won't unexpectedly have files deleted because they haven't modified their global-ignores parameter yet.这样,当人们更新时,他们不会意外删除文件,因为他们还没有修改他们的global-ignores参数。

I was able to do this by using the TortoiseSVN tool.我可以通过使用TortoiseSVN工具来做到这一点。 They provide a GUI right-click option named: "Delete and add to ignore list".他们提供了一个名为“删除并添加到忽略列表”的 GUI 右键单击​​选项。

svn remove filename

Ignoring:忽略:

svn propset svn:ignore filename|pattern

See also How to … Make Subversion ignore files and folders .另请参阅如何...使 Subversion 忽略文件和文件夹

Thanks for this answer exactly what I needed.感谢这个答案正是我所需要的。 One thought on the final script outlined above, wouldn't it be better in your script to do a svn export instead of cp -R?关于上面概述的最终脚本的一个想法,在您的脚本中执行 svn 导出而不是 cp -R 不是更好吗? That way you'd get clean folders without any of the .svn folders.这样你就可以得到没有任何 .svn 文件夹的干净文件夹。

eg例如

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

Anyway just a thought ...无论如何只是一个想法......

如果你想让它们永远消失(或者直到你自己添加它们),你svn rm它们,commi 并将它们添加到.svnignore

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM