Programing

작업 사본에서 버전없는 / 무시 된 파일 / 폴더를 모두 삭제하려면 어떻게해야합니까?

lottogame 2020. 6. 29. 08:03
반응형

작업 사본에서 버전없는 / 무시 된 파일 / 폴더를 모두 삭제하려면 어떻게해야합니까?


Subversion 저장소의 작업 사본이있는 경우 단일 명령 또는 도구를 사용하여 작업 사본에서 버전이 없거나 무시 된 모든 파일을 삭제하는 방법이 있습니까? 본질적으로 SVN 아날로그를 찾고 git clean있습니다.

TortoiseSVN의 경우 명령 줄 또는 GUI 솔루션을 사용할 수 있습니다.


TortoiseSVN 사용 :

  • Shift 키를 누른 상태 에서 작업중 인 복사 폴더를 마우스 오른쪽 버튼으로 클릭하십시오.
  • "버전없는 항목 삭제"를 선택하십시오.

svn status --no-ignore | grep '^[I?]' | cut -c 9- | while IFS= read -r f; do rm -rf "$f"; done

여기에는 다음과 같은 기능이 있습니다.

  • 무시되고 추적되지 않은 파일이 모두 삭제됩니다
  • 파일 이름에 공백이 포함되어 있어도 작동합니다 (개행 제외). --xml옵션을 사용 하고 결과 xml 출력을 구문 분석하는 것 외에는 수행 할 수있는 것이 많지 않습니다 )
  • svn status파일 이름 앞에 다른 상태 문자를 인쇄 하더라도 작동 합니다 (파일을 추적하지 않기 때문에 경우에 대비하여 ...)
  • POSIX 호환 시스템에서 작동해야합니다.

svnclean다음을 포함 하는 쉘 스크립트를 사용합니다 .

#!/bin/sh

# make sure this script exits with a non-zero return value if the
# current directory is not in a svn working directory
svn info >/dev/null || exit 1

svn status --no-ignore | grep '^[I?]' | cut -c 9- |
# setting IFS to the empty string ensures that any leading or
# trailing whitespace is not trimmed from the filename
while IFS= read -r f; do
    # tell the user which file is being deleted.  use printf
    # instead of echo because different implementations of echo do
    # different things if the arguments begin with hyphens or
    # contain backslashes; the behavior of printf is consistent
    printf '%s\n' "Deleting ${f}..."
    # if rm -rf can't delete the file, something is wrong so bail
    rm -rf "${f}" || exit 1
done

나는 이것이 그 위에 오래된하지만의 경우 다른 사람 비틀 거림, SVN 지원의 최신 버전 (1.9 이상)을 알고 --remove-unversioned, 예 svn cleanup . --remove-unversioned.

https://subversion.apache.org/docs/release-notes/1.9.html#svn-cleanup-options


이 oneliner가 도움이 될 수 있습니다.

$ svn status | grep '^?' | awk '{print $2}' | xargs rm -rf

조심해서 사용하십시오!


Powershell을 사용하여 Yanal-Yves Fargialla 및 gimpf의 답변 수정 (스택 오버 플로우에서 원래 게시물에 댓글을 달 수는 없음) :

powershell -Command "&{(svn status --no-ignore) -match '^[\?i]' -replace '^.\s+' | rm -recurse -force}

이렇게하면 캐럿 ( "^")이 추가되어 줄의 시작을 지정하여 문자 "i"를 포함하는 모든 파일과 일치하지 않습니다. 또한 -recurse 및 -force에 대한 플래그를 rm에 추가하여이 명령을 대화식이 아니므로 스크립트에서 사용할 수있게하십시오.


SVN의 많은 것들이 여기에 주어진 다양한 명령 줄 답변에 의해 입증 된 것처럼 다른 방식으로 수행 될 수 있습니다. 버전 1.7이 등장함에 따라 TortoiseSVN에는 스테판의 대답보다 더 세밀한 해상도를 제공하는 또 다른 기술이 있습니다. 이는 버전이없는 파일을 무시 된 파일과 별도로 선택할 수있게합니다. TortoiseSvn >> Clean up...이 대화 상자를 열려면 선택하십시오 .

TortoiseSVN 정리 옵션


Powershell 사용시 :

(svn status --no-ignore) -match '[?]' -replace '^.\s+' | rm

명령 행에서 :

powershell -Command "&{(svn status --no-ignore) -match '[?]' -replace '^.\s+' | rm}"

이 oneliner는 나를 위해 일합니다 (리차드 한센의 대답에 따르면 놀랍게도 공백이있는 파일에는 작동하지 않았습니다).

svn status --no-ignore | grep '^[I?]' | cut -c 9- | xargs -d"\n" -I{} rm {}

TortoiseSVN 사용 :

  1. Right-Click on the root of the working copy and select TortoiseSVN -> "check for modifications"
  2. Select "Show ignored files"
  3. Sort by "Text status" column
  4. scroll to the "non-versioned" files, now all grouped together; select them all and right-click -> delete
  5. scroll to the "ignored" files, now all grouped together; select them all and right-click -> delete

Not really a nice and clean solution, but the fastest way I know of (on Windows).

Thanks to pkh for the tip with the ignored files.


This is similar to other answers, but actually gets ignored files (note the 'I' in the REs):

 rm -rf `svn status --no-ignore | grep '^[\?I]' | sed 's/^[\?I]//'`

Somebody said you can't do it from the Windows command line.

Bull.

for /f "tokens=2 delims= " %I IN ('svn st --no-ignore ^| findstr /R "^[I?]"') DO (DEL /S /F /Q /A:H "%I" & rmdir /S /Q "%I")

Does it in one line and doesn't require a single GNU tool. :)


리눅스 시스템을 사용하는 경우 SVN 명령 줄 (GUI 도구는 확실하지 않음)로 삭제할 수 없습니다.

http://www.guyrutenberg.com/2008/01/18/delete-unversioned-files-under-svn/

다른 (잔인한) 방법은 변경 사항을 커밋하고 폴더에서 모두 삭제 한 후 다시 체크 아웃하는 것입니다.

참고 URL : https://stackoverflow.com/questions/2803823/how-can-i-delete-all-unversioned-ignored-files-folders-in-my-working-copy

반응형