由於編譯或打開項目文件而導致多次創建臨時文件。我希望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