简体   繁体   中英

How to delete broken commits in git that has commit id but not readable

I have a repo that when I run git fsck --full , I got a long list of broken commit ids:

Checking object directories: 100% (256/256), done.
Checking objects: 100% (861/861), done.
error: Could not read 0f514378e088c610cbeb8b047c63d4209736d1f9
failed to parse commit 0f514378e088c610cbeb8b047c63d4209736d1f9 from object database for commit-graph
error: Could not read 1e77fe5a6c4bec9bc9bd7ac5c00f2bbe98249b44
failed to parse commit 1e77fe5a6c4bec9bc9bd7ac5c00f2bbe98249b44 from object database for commit-graph
error: Could not read 2a86db8a8c83ac0fdb5050efa63b518fbeaf8146
failed to parse commit 2a86db8a8c83ac0fdb5050efa63b518fbeaf8146 from object database for commit-graph
error: Could not read 2d898d27a8858cfba7db93f79ada3bdca181758d
failed to parse commit 2d898d27a8858cfba7db93f79ada3bdca181758d from object database for commit-graph
...
error: Could not read fc80facb8f8bf3a5972c51b2e9ae5e63552db2f0
failed to parse commit fc80facb8f8bf3a5972c51b2e9ae5e63552db2f0 from object database for commit-graph
Verifying commits in commit graph: 100% (28/28), done.

I just could not figure out how to delete them. I tried git gc , git prune , none of them works...

also I have a commit that can be shown as diff with git show <commit_id> , but when I run git branch --contains <commit_id> , no branch is found, so I believe that is a dangling commit, but again, I tried everything I found on google. None works.

The commands I tried.

git prune --expire now
git gc --prune=now
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch filename --prune-empty --tag-name-filter cat -- --all"
...

I have fixed this with the following command:

docker exec -t GitLab git -C /var/opt/gitlab/git-data/repositories/@hashed/30/48/3148905660916d5dde3add79e63f095af3ffb81604691f21cad442a85c7be617.git commit-graph write

I use the Docker Omnibus version so your command might vary a bit. In the path after @hashed, you can find your repo path in the admin section of the GitLab project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM