由于编译或打开项目文件而导致多次创建临时文件。我希望SVN忽略(不是版本)这些文件,而不必全局忽略它们,因为不同的程序/进程可能在别处创建它们,并且可能需要版本控制(相同的扩展名不同的文件类型)。使用Bash和SVN做这件事的最好方法是什么?我创建的以下bash脚本是否足够?递归地忽略SVN中的文件或目录模式而不会全局忽略的最佳方式
# Recursively find, remove, and set svn:ignore on files or folders.
# For safety, you must perform an svn status and an svn commit yourself.
#
# $1 is the pattern to ignore
# $2 is the starting directory (optional)
# $3 is a flag to remove the ignored files locally (optional)
#
# Example: recursive_svn_ignore "*.bak" . --remove
#
recursive_svn_ignore()
{
cd "$2";
svn info > /dev/null 2>&1;
if [ "$?" -ne "0" ]; then
echo "Skipping `pwd` because it is not under version control.";
return 1;
fi;
# Check if pattern matches
ls -l $1 > /dev/null 2>&1;
if [ "$?" = "0" ]; then
for f in "$1"; do
if [ "$3" = "--remove" ]; then
# Remove file from working directory and repository
svn rm --force -q $f;
else
# Remove file from repository only
svn rm --force --keep-local $f;
fi;
done
echo "Adding "$1" in `pwd` to svn:ignore list";
svn propget svn:ignore . > svnignore.tempfile;
echo "$1" >> svnignore.tempfile;
svn propset -q svn:ignore -F svnignore.tempfile .;
rm svnignore.tempfile;
fi;
# Recurse
for d in *
do
if [ -d "$d" ]; then
(recursive_svn_ignore "$1" "$d")
fi;
done
}
至于建议由@大卫面包车,边缘,使用find
通过消除递归简化了很多东西。这是我想出的。
#!/bin/bash
# Recursively find and set svn:ignore on files or folders.
# If the file was already version it will be removed from the repository
# and keep the local copy (can be overridden).
# This does not perform the final commit so you can review the changes
# using svn status.
#
# $1 pattern to ignore
# $2 remove the ignored files locally as well (optional)
#
# Example: find_svn_ignore "*.bak" . --remove
#
for a in `find . -name $1`
do
svn info ${a%/*} > /dev/null 2>&1;
if [ "$?" -ne "0" ]; then
echo "Skipping ${a%/*} because it is not under version control.";
continue;
fi;
echo "Ignoring ${a##*/} in ${a%/*}";
svn propget svn:ignore ${a%/*} > svnignore.tempfile;
echo "$1" >> svnignore.tempfile;
svn propset -q svn:ignore -F svnignore.tempfile ${a%/*};
rm svnignore.tempfile;
if [ "$2" = "--remove" ]; then
# Remove file from working directory and repository
svn rm --force -q ${a##*/};
else
# Remove file from repository only
svn rm --force --keep-local ${a##*/};
fi;
done
这是David W.的一个好点,我希望能够自动提醒人们这样的政策。我会试试这个。我仍然需要一种轻松设置svn:ignore的方法,David V. B.帮助简化了我的生活。感谢你们俩。 – Lucas 2011-08-18 17:25:48