분기가없는 Git 커밋 나열 및 삭제 (댕글?)
특정 분기 아래에 많은 커밋이있는 Git 리포지토리가 git show
있습니다.하지만 해당 분기가 포함 된 분기를 나열하려고하면 아무것도보고하지 않습니다.
나는 이것이 -D 브랜치의 결과로 매달려있는 커밋 / 트리 문제라고 생각했기 때문에 리포지를 정리했지만 여전히 그 후에도 동일한 동작을 봅니다.
$ git fetch origin
$ git fsck --unreachable
$ git fsck
출력도없고 매달려있는 것도 없습니다 (오른쪽?). 그러나 커밋이 존재합니다.
$ git show 793db7f272ba4bbdd1e32f14410a52a412667042
commit 793db7f272ba4bbdd1e32f14410a52a412667042
Author: ...
그리고 그것은 어떤 지점을 통해서도 도달 할 수 없습니다
$ git branch --contains 793db7f272ba4bbdd1e32f14410a52a412667042
출력을 제공하지 않습니다.
그 커밋의 상태는 정확히 무엇입니까? 모든 커밋을 유사한 상태로 나열하려면 어떻게해야합니까? 그런 커밋을 어떻게 삭제합니까?
출력이없고 매달려있는 것이 없습니다 (맞습니까?)
참조 로그에서 언급 된 커밋은 도달 가능한 것으로 간주됩니다.
그 커밋의 상태는 정확히 무엇입니까? 비슷한 상태의 모든 커밋을 나열하는 방법
패스 --no-reflogs
설득하는 git fsck
당신에게 보여.
그런 커밋을 어떻게 삭제합니까?
reflog 항목이 만료되면 해당 객체도로 정리됩니다 git gc
.
만기가에 의해 규제되고 gc.pruneexpire
, gc.reflogexpire
및 gc.reflogexpireunreachable
설정. Cf. git help config
.
기본값은 모두 합리적입니다.
매달린 커밋과 reflog에서 도달 가능한 커밋을 제거하려면 다음을 수행하십시오.
git reflog expire --expire-unreachable=now --all
git gc --prune=now
그러나 이것이 당신이 원하는 것임을 확신하십시오. 맨 페이지를 읽는 것이 좋지만 여기 요점이 있습니다.
git gc
도달 할 수없는 객체 (커밋, 트리, 얼룩 (파일))를 제거합니다. 일부 분기의 내역에 포함되지 않은 개체에 도달 할 수 없습니다. 실제로는 조금 더 복잡합니다.
git gc
다른 일을하지만 여기서는 관련이 없으며 위험하지 않습니다.
2 주 미만의 도달 할 수없는 개체는 제거되지 않으므로 --prune=now
"이전에는 만든 연결할 수없는 개체 제거"를 의미합니다.
reflog를 통해 객체에 접근 할 수도 있습니다. 브랜치는 일부 프로젝트의 이력을 기록하지만 리플 로그는이 브랜치의 이력을 기록합니다. 수정하면 재설정 등의 커밋이 브랜치 히스토리에서 제거되지만 git은 실수를 저지른 경우를 대비하여 커밋을 유지합니다. Reflogs는 브랜치 (또는 HEAD)에서 수행 된 파괴적인 (및 기타) 조작을 찾는 편리한 방법으로 파괴적인 조작을보다 쉽게 취소 할 수 있습니다.
따라서 지점에서 도달 할 수없는 모든 것을 실제로 제거하려면 reflog를 제거해야합니다. 우리는 --all
reflog 를 만료 시켜서 그렇게합니다 . 다시 git은 사용자를 보호하기 위해 약간의 reflog를 유지하므로 그렇게하지 말라고 다시 지시해야 --expire-unreachable=now
합니다.
필자는 파괴적인 작업에서 복구하기 위해 주로 reflog를 사용하기 때문에 --expire=now
대신 일반적으로 reflog를 완전히 방해합니다.
이 스레드의 모든 조언을 따른 후에도 동일한 문제가 발생했습니다.
git reflog expire --expire-unreachable=now --all
git gc --prune=now
git fsck --unreachable --no-reflogs # no output
git branch -a --contains <commit> # no output
git show <commit> # still shows up
참조가 아닌 분기가 아닌 경우 ... 태그 여야합니다 !
git tag # showed several old tags created before the cleanup
git tag -d <tagname>
정리 태그를 제거하고 정리를 다시 수행했는데 이전 커밋이 사라졌습니다.
git branch --contains 793db7f272ba4bbdd1e32f14410a52a412667042
아마 단지
git branch -a --contains 793db7f272ba4bbdd1e32f14410a52a412667042
리모컨의 분기에 대해서도보고합니다
나는 비슷한 문제가 있었다. 나는 실행 git branch --contains <commit>
했고 질문에서와 같이 출력을 반환하지 않았습니다.
But even after running
git reflog expire --expire-unreachable=now --all
git gc --prune=now
my commit was still accessible using git show <commit>
. This was because one of the commits in its detached/dangled "branch" was tagged. I removed the tag, ran the above commands again, and I was golden. git show <commit>
returned fatal: bad object <commit>
- exactly what I needed. Hopefully this helps someone else that was as stuck as I was.
git gc --prune=<date>
defaults to prune objects older than two weeks ago. You could set a more recent date. But, git commands that create loose objects generally will run git gc --auto (which prunes loose objects if their number exceeds the value of configuration variable gc.auto).
Are you sure that you want to delete these commits? gc.auto's default setting will ensure that the loose objects do not take up an unreasonable amount of memory, and storing loose objects for some amount of time is generally a good idea. That way, if you realize tomorrow that your deleted branch contained a commit you needed, you can recover it.
I accidentally hit the same situation and found my stashes contain reference to the unreachable commit, and thus the presumed unreachable commit was reachable from stashes.
These were what I did to make it truly unreachable.
git stash clear
git reflog expire --expire-unreachable=now --all
git fsck --unreachable
git gc --prune=now
'programing tip' 카테고리의 다른 글
위도 / 경도 좌표가 주어지면 도시 / 국가를 어떻게 알 수 있습니까? (0) | 2020.06.29 |
---|---|
기본 long 배열을 Long 목록으로 변환 (0) | 2020.06.29 |
jQuery를 사용하여 선택 상자에서 첫 번째 옵션을 설정하는 방법은 무엇입니까? (0) | 2020.06.29 |
Angular 컴파일러의 오류에는 TypeScript> = 3.1.1 및 <3.2.0이 필요하지만 대신 3.2.1이 발견되었습니다. (0) | 2020.06.29 |
LINQPad [확장] 방법 (0) | 2020.06.29 |