IT story

git 저장소에서 병합 한 후 .orig 파일을 삭제하는 방법은 무엇입니까?

hot-time 2020. 6. 19. 07:59
반응형

git 저장소에서 병합 한 후 .orig 파일을 삭제하는 방법은 무엇입니까?


병합 중에 git 저장소에서 .orig 파일을 확인하는 방법이 수정되었으며 추적되지 않은 섹터에 표시됩니다. 그러나 더 이상 내 저장소 에이 파일을 원하지 않습니다. 그렇게하는 방법.

    modified:   Gemfile.lock.orig
    #   modified:   Gemfile.orig
    #   modified:   app/assets/images/bg_required.png.orig
    #   modified:   app/assets/javascripts/application.js.orig

    etc...

도움을 주시면 감사하겠습니다.


이 경우 가장 좋은 해결책은 간단하게 유지하고 git과 독립적으로 해당 파일을 제거하는 것입니다.

cd /your/repo/directory
find . -name '*.orig' -delete 

또는 Windows / PowerShell에서 다음 명령을 실행할 수 있습니다.

cd \your\repo\directory
Get-ChildItem -Recurse -Filter '*.orig' | Remove-Item

여기 또는 여기 에서git clean 더 많은 정보를 찾아 보십시오


넌 할 수있어:

git config --global mergetool.keepBackup false

자세한 내용은 Git mergetool이 원치 않는 .orig 파일을 생성 함 을 참조하십시오.


.gitignore를 사용하여 파일을 무시할 수 있습니다

여기에 표시된 것처럼 * .orig를 목록에 넣으십시오.

https://help.github.com/articles/ignoring-files

현재 파일을 삭제하려면 다음과 같이 쉘 스크립트를 작성하고 프로젝트 폴더에서 실행할 수 있습니다

for file in `find *.orig -type f -print`
do
   echo "Deleting file $file"
   git rm $file -f       
done

불행히도 전역 gitignore 파일에 추가 git clean했기 때문에 작동하지 않으므로 *.orig깨끗 하지 않습니다 . 심지어 실행은 git clean -x내가 원하지 않기 때문에 좋지 않습니다 모든 내 무시 파일 삭제하기. git clean -i도움이 되긴하지만 실제로 모든 파일을 검토하고 싶지는 않습니다.

그러나 제외 패턴을 사용하고 일치를 무효화 할 수 있습니다. 이 명령으로 미리보기 :

git clean -e '!*.orig' --dry-run

그런 다음 확신이있을 때 force플래그를 전달하여 실제로 삭제하십시오.

git clean -e '!*.orig' -f

leorleor의 의견을 바탕으로


git rm Gemfile.lock.orig 나머지 파일은 필요하지 않습니다. git commit --amend

해당 얼룩을 완전히 제거하려면 git gc --prune=0 --aggressive


나를 위해 git clean -f모든 * .oig 파일을 제거했습니다. 그리고 이전에 이미 존재했던 것들을 유지합니다.

이것은 병합 후 (거의) 모습입니다.

$ git status
On branch feature/xyz
Your branch is ahead of 'origin/feature/xyz' by 568 commits.
  (use "git push" to publish your local commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    .idea/codeStyles/
    .idea/misc.xml.orig

.idea/codeStyles/추적되지 않은 파일로 병합하기 전에 이미있었습니다. .idea/misc.xml.orig(그리고 훨씬 더) 제거해야했습니다.

=> 사용 git clean -f:

$ git clean -f
Removing .idea/misc.xml.orig

결과 :

$ git status
On branch feature/xyz
Your branch is ahead of 'origin/feature/xyz' by 568 commits.
  (use "git push" to publish your local commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    .idea/codeStyles/

당신은 단순히 할 수 있습니다 git status -s | grep "\.orig$" | awk '{print $2}' | xargs -n1 -r echo rm

TL; DR;

git status -s 색인과 관련하여 수정되거나 누락 된 모든 파일을 가져올 수 있습니다

grep "\.orig$" ".orig"로 끝을 유지하면서 파일을 필터링

awk '{print $2}' 파일 이름을 나열합니다 (git 정보 건너 뛰기 (예 : A, M, ??))

xargs -n1 -r echo rm 모든 인수에 대한 제거 명령을 인쇄합니다 (-n1 : 한 번에 하나씩 -r : 비어 있으면 건너 뛰기). 제거 할 파일을 두 번 확인하여 명령을 복사하여 붙여 넣습니다.


git rm <file>

http://git-scm.com/docs/git-rm

또한 무시하려는 파일 / 디렉토리를 .gitignore 파일에 추가하십시오.

참고URL : https://stackoverflow.com/questions/12366150/how-to-delete-orig-files-after-merge-from-git-repository

반응형