디렉토리를 .gitignore에 추가한 후 원격 저장소에서 제거합니다.
github에 .후 , 는, 나 the after나 the the the the the 、 the 、 、 after 、 。.gitignore무시해야 할 디렉토리를 추가하는 파일.모든 것이 정상적으로 동작하지만 (현재 무시되고 있는) 디렉토리는 github에 남습니다.
github 및 저장소 기록에서 해당 디렉토리를 삭제하려면 어떻게 해야 합니까?
의 .gitignore파일에서 커밋되어 있기 하여 GitHub 에 .
git rm -r --cached some-directory
git commit -m 'Remove the now ignored directory "some-directory"'
git push origin master
리포지토리 기록을 다시 작성하지 않고 기록에서 파일을 삭제할 수 없습니다. 다른 사용자가 리포지토리로 작업하거나 여러 컴퓨터에서 파일을 사용하는 경우 이 작업을 수행하지 마십시오.그래도 그렇게 하고 싶다면git filter-branch여기 도움이 되는 가이드가 있습니다.
,, 음, addition 、 음 、 음 、 음 、 음 、 음 、 from 、 from 、 from 、 。git rm -r --cached some-directory음음음같 뭇매하다
rm 'some-directory/product/cache/1/small_image/130x130/small_image.jpg'
rm 'some-directory/product/cache/1/small_image/135x/small_image.jpg'
rm 'some-directory/.htaccess'
rm 'some-directory/logo.jpg'
rm기트이치노
첫 번째 솔루션:
git rm --cached `git ls-files -i -c --exclude-from=.gitignore`
git commit -m 'Removed all files that are in the .gitignore'
git push origin main
그러면 git ignore에 있는 모든 파일/폴더가 삭제되고, 각각의 파일을 수동으로 선택해야 합니다.
두 번째 해결책: 로컬 git 저장소에서 파일을 삭제합니다.git rm - r -- cached . git add . git commit - m ' . gitignore " git push origin main "에 있는 모든 파일 삭제
--cached 플래그는 git 저장소에서 파일을 삭제하지만 파일 시스템에서는 삭제하지 않습니다.
제 답변은 다음과 같습니다.git 저장소에서 디렉토리를 삭제하려면 어떻게 해야 합니까?
폴더/디렉토리를 로컬 저장소가 아닌 git 저장소에서만 삭제하려면 3가지 간단한 단계를 수행하십시오.
디렉토리를 삭제하는 순서
git rm -r --cached FolderName
git commit -m "Removed folder from repository"
git push origin master
다음 커밋에서 해당 폴더를 무시하는 단계
다음 커밋에서 해당 폴더를 무시하려면 .gitignore라는 이름의 루트에 하나의 파일을 만들고 해당 폴더 이름을 넣습니다.원하는 만큼 넣어도 된다.
.syslogignore 파일은 다음과 같습니다.
/FolderName

블런델의 첫 번째 대답은 나에게 효과가 없었다.하지만 그것은 나에게 올바른 길을 가르쳐 주었다.나도 같은 일을 해봤다.
> for i in `git ls-files -i --exclude-from=.gitignore`; do git rm --cached $i; done
> git commit -m 'Removed all files that are in the .gitignore'
> git push origin master
먼저 다음 명령어를 실행하여 삭제할 파일을 확인하는 것이 좋습니다.
git ls-files -i --exclude-from=.gitignore
비주얼 스튜디오에 기본 .gitignore 파일을 사용하고 있었는데 프로젝트의 모든 로그 및 bin 폴더가 삭제되고 있는 것을 알게 되었습니다.이것은 의도한 액션이 아닙니다.
주의: 이 솔루션은 Github Desktop GUI에서만 작동합니다.
Github Desktop GUI를 사용하면 매우 간단합니다.
폴더를 일시적으로 다른 위치(프로젝트 폴더 외부)로 이동합니다.
의 편집
.gitignoregithub 페이지에서 마스터 저장소를 삭제할 폴더 엔트리를 파일화하여 삭제합니다.프로젝트 폴더를 커밋하고 동기화합니다.
폴더를 프로젝트 폴더로 다시 이동합니다.
재편집
.gitignore파일.
그게 다예요.
이 메서드는 표준 .gitignore 동작을 적용하므로 무시해야 하는 파일을 수동으로 지정할 필요가 없습니다.
사용할 수 없음
--exclude-from=.gitignoremore more : / - 갱신된 방법은 다음과 같습니다.일반적인 조언: 깨끗한 보고서부터 시작하여 커밋된 모든 내용, 작업 디렉토리 또는 인덱스에 보류 중인 내용 없음, 백업을 만듭니다.
#commit up-to-date .gitignore (if not already existing)
#this command must be run on each branch
git add .gitignore
git commit -m "Create .gitignore"
#apply standard git ignore behavior only to current index, not working directory (--cached)
#if this command returns nothing, ensure /.git/info/exclude AND/OR .gitignore exist
#this command must be run on each branch
git ls-files -z --ignored --exclude-standard | xargs -0 git rm --cached
#optionally add anything to the index that was previously ignored but now shouldn't be:
git add *
#commit again
#optionally use the --amend flag to merge this commit with the previous one instead of creating 2 commits.
git commit -m "re-applied modified .gitignore"
#other devs who pull after this commit is pushed will see the newly-.gitignored files DELETED
지점의 커밋 기록에서 새로 무시된 파일도 삭제해야 하거나 새로 무시된 파일을 나중에 꺼낼 때 삭제하지 않으려면 다음 답변을 참조하십시오.
블런델의 답변은 효과가 있을 겁니다. 하지만 어떤 기이한 이유에선지 나와는 상관없는 일이었습니다.먼저 첫 번째 명령어로 출력된 파일 이름을 파일로 파이핑한 후 해당 파일을 루프하여 하나씩 삭제해야 했습니다.
git ls-files -i --exclude-from=.gitignore > to_remove.txt
while read line; do `git rm -r --cached "$line"`; done < to_remove.txt
rm to_remove.txt
git commit -m 'Removed all files that are in the .gitignore'
git push origin master
Windows 머신에서 Blundell에 의해 기술된 기술(모두 삭제 후 모두 추가)을 사용하고 있는 경우, 행의 끝이 변경되기 때문에 모든 파일이 수정되는 문제가 발생할 수 있습니다.이를 방지하려면 다음 명령을 사용합니다.
git rm -r --cached .
git config --global core.autocrlf false
git add --renormalize .
git add .
그러면 인덱스에서 모든 파일이 삭제되고 git이 행 엔딩을 변경하지 않도록 설정되며 행 엔딩이 다시 정규화되어 에서 지정된 파일을 제외한 모든 파일이 스테이징됩니다..gitignore
그리고나서git commit
레퍼런스:공백을 변경하지 않고 .gitignore에 나열된 저장소에서 파일을 삭제하는 방법
Windows 유저에게 있어서, 이것은 매우 효과적이었다.
git ls-files -i -c --exclude-from=.gitignore | %{git rm --cached $_}
git add .
git commit -m "Remove files from .gitignore"
PowerShell에서 작업하는 경우 다음 명령을 한 번에 사용해 보십시오.
PS MyRepo> git filter-branch --force --index-filter
>> "git rm --cached --ignore-unmatch -r .\\\path\\\to\\\directory"
>> --prune-empty --tag-name-filter cat -- --all
그리고나서,git push --force --all.
문서: https://git-scm.com/docs/git-filter-branch
언급URL : https://stackoverflow.com/questions/7927230/remove-directory-from-remote-repository-after-adding-them-to-gitignore
'source' 카테고리의 다른 글
| 스타일의 TargetType 속성을 기본 클래스로 설정 (0) | 2023.04.13 |
|---|---|
| SQL Server - 부울 리터럴? (0) | 2023.04.13 |
| Objective-C에서 절대값으로 변환 (0) | 2023.04.13 |
| XAML의 읽기 전용 속성에서 OneWayToSource 바인딩 (0) | 2023.04.13 |
| Excel 셀에서의 변수 선언 (0) | 2023.04.13 |