svn用命令添加ignore或者清除ignore列表

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

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

回答:

30

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.

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

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.

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

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

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

Create either your global-ignores entry or add the svn:ignore property to your repository and commit.
For each file that you want to remove from the repository, issue this command: svn rm --keep-local filename
Once you've issued the svn rm command for each file, commit your working copy.
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.

shareimprove this answer
edited Jan 25 '13 at 8:34

rob74
2,8711426
answered Jan 5 '09 at 23:31

Jason Coco
73.1k19174176
That's a good explanation of the correct set-up and I will henceforth ensure my global ignores file is adjusted to void this happening. It doesn't answer my original problem though of removing a file from SVN and having it ignored without having to delete the file and replace it. – DavidWinterbottom Jan 6 '09 at 11:29
hey David - sorry about that, I guess I didn't read the question properly :) I've updated the answer a bit at the bottom... HTH! J – Jason Coco Jan 6 '09 at 12:54
Part of this answer is wrong. Using keep-local will only work for the person rm'ing the files. Everyone else will have their local copies deleted when they update. – blahdiblah Jun 2 '11 at 18:32
From now on, the build directory in your project will be ignored by subversion That is true, but only until another folder is ignored! Let's say that you also want to ignore the temp folder. If you run the command to ignore that then suddenly the build folder will no longer be ignored! See this answer for how to ignore multiple items. – Roger Nov 11 '16 at 18:53 
二、忽略多个目录

如果有多个目录需要删除,逐个目录按照上面步骤操作,那么操作完成后,前面操作的目录执行svn st又会显示成 ? 状态,而最后执行的那个目录才不会显示出来,所以说这样前面的目录都白弄了
如果有多个目录需要同时忽略,需要这样弄

[root@localhost adv]# svn st
? ad
? material
? logs
? images
[root@localhost adv]# svn delete url -m="delete ad"    #删除版本库相应目录
[root@localhost adv]# mv ad material logs images /tmp	  #先备份
[root@localhost adv]# svn propset svn:ignore ".svnignore
> ad
> material
> logs
> images
> " ./
property 'svn:ignore' set on '.'
[root@localhost adv]# svn propget svn:ignore .
.svnignore
ad
material
images
logs

[root@localhost adv]# svn ci -m "ignore some directory"
Sending adv

Committed revision 6.
[root@localhost adv]# svn st
[root@localhost adv]#mv /tmp/{ad,images,logs,material} ./  #恢复备份

到这里就大功告成了,无论怎么修改上面的几个目录里面文件svn st都不会列出来,无论怎么svn up当前目录,上面几个目录都不会受到影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值