programing

손상된 Git 저장소를 어떻게 고칠 수 있습니까?

closeapi 2023. 8. 29. 20:39
반응형

손상된 Git 저장소를 어떻게 고칠 수 있습니까?

Ubuntu One 폴더에 보관 중인 저장소를 새 컴퓨터로 복제하려고 시도했는데 다음과 같은 결과가 나왔습니다.

cd ~/source/personal
git clone ~/Ubuntu\ One\ Side\ Work/projects.git/

Cloning into 'projects'...
done.
fatal: unable to read tree 29a422c19251aeaeb907175e9b3219a9bed6c616

그래서 저는 여기서 이와 같은 많은 다른 질문들을 보려고 노력했고 그들 대부분은 출마하라고 말합니다.git fsck --full시도해보면 이런 느낌이 들어요.

cd ~/Ubuntu\ One\ Side\ Work/projects.git
git fsck --full

Checking object directories: 100% (256/256), done.
Checking objects: 100% (447/447), done.
broken link from  commit 235ae1f48701d577d71ebd430344a159e5ba4881
              to  commit 984c11abfc9c2839b386f29c574d9e03383fa589
broken link from    tree 632a9cf0ef9fccea08438b574e2f1c954f4ff08b
              to    blob 25a742dff0a403b2b3884f2ffddf63eb45721fac
broken link from    tree 632a9cf0ef9fccea08438b574e2f1c954f4ff08b
              to    blob dd4e97e22e159a585b20e21028f964827d5afa4e
broken link from    tree 632a9cf0ef9fccea08438b574e2f1c954f4ff08b
              to    tree 29a422c19251aeaeb907175e9b3219a9bed6c616
broken link from    tree 632a9cf0ef9fccea08438b574e2f1c954f4ff08b
              to    tree 8084e8e04d510cc28321f30a9646477cc50c235c
broken link from    tree 774b5b4157b4caae1c6cad96c8eaf5d4eba2c628
              to    blob a0daa0c1567b55d8de2b4d7a3bc010f58c047eab
broken link from    tree 774b5b4157b4caae1c6cad96c8eaf5d4eba2c628
              to    blob e9052d35bfb6d30065b206fc43f4200a04d5281b
broken link from    tree 774b5b4157b4caae1c6cad96c8eaf5d4eba2c628
              to    blob 1a3a5e4dd2502ac121c22f743c4250e254a94eeb
broken link from    tree 4aa336dc1a5838e8918e03b85580069d83f4ad09
              to    tree 8cc55ec952dc192a233e062201d1e7e873ac3db0
broken link from    tree e5674a91a53e15575a1f3bf5786bc5cc719fb483
              to    blob 4a994e1e7bb7ce28dcec98bad48b9a891d7dec51
broken link from    tree e5674a91a53e15575a1f3bf5786bc5cc719fb483
              to    blob ac033bf9dc846101320c96a5ce8aceb8c96ec098
broken link from    tree 252ab84542264e1589576b6ee51e7a31e580a0e2
              to    tree 2069041cd5950e529e2991d37b7290ec021d90d4
broken link from    tree 2d4964aa4d4f5d8c7228518ce72ef6a63f820c6d
              to    blob d83690e1b9a6bdd8a08754b38231799acefcb2ab
broken link from    tree c7192e82fc581bd6448bda1a25e8729bdac5f4ff
              to    blob 30d54d47ae82add1917ca173d42e58b396df580b
broken link from    tree 7c66306901fc71389623286936cef172d4ffe408
              to    blob bc7e05d705401273b1df4e939de0f540597c0931
broken link from    tree 0940f5fd227d4c84d6e6749d872db50a4522ae3a
              to    tree 923767594ac22023e824948d65622fe5b407d1a1
broken link from    tree 8eadcd2a971e8357d24f0d80f993d2963452209f
              to    blob 2598bde3dc8cb80ee49510b8159344004b88645f
broken link from    tree ffa302dd0d969172ef23caeefe856ab2f57a4e4d
              to    blob d6925fa431be1ac585bf9a481e98f75107a6e6fb
broken link from    tree 7045b8870a49ce30a2027537a96d73d162bda773
              to    blob 25688652dea26f61f576ca1b52b9d1a18fbfd01d
broken link from    tree 37e4705d34bd440ce681ae32ae9a180a13256d72
              to    tree 246f564d4cee53339b8a4244f3173b61caa518eb
missing blob d6925fa431be1ac585bf9a481e98f75107a6e6fb
missing blob ac033bf9dc846101320c96a5ce8aceb8c96ec098
missing tree 29a422c19251aeaeb907175e9b3219a9bed6c616
missing tree 8084e8e04d510cc28321f30a9646477cc50c235c
missing blob 30d54d47ae82add1917ca173d42e58b396df580b
missing tree 8cc55ec952dc192a233e062201d1e7e873ac3db0
missing blob e9052d35bfb6d30065b206fc43f4200a04d5281b
dangling tree 4b26e95db542c72ac4a22ec25abe38fb2de79752
missing blob d83690e1b9a6bdd8a08754b38231799acefcb2ab
missing blob 25a742dff0a403b2b3884f2ffddf63eb45721fac
missing tree 923767594ac22023e824948d65622fe5b407d1a1
missing blob 25688652dea26f61f576ca1b52b9d1a18fbfd01d
missing blob 2598bde3dc8cb80ee49510b8159344004b88645f
dangling tree 3a683869f1bb0c1634de75700c316b3b36570dbd
dangling blob 4098d30843380d798a811f1aa9a02994f0dbbb27
missing tree 2069041cd5950e529e2991d37b7290ec021d90d4
missing blob 4a994e1e7bb7ce28dcec98bad48b9a891d7dec51
missing blob 1a3a5e4dd2502ac121c22f743c4250e254a94eeb
missing blob a0daa0c1567b55d8de2b4d7a3bc010f58c047eab
dangling tree 6c7b5162aa7a303fa3fe8dc393c5da564e309521
missing commit 984c11abfc9c2839b386f29c574d9e03383fa589
missing blob bc7e05d705401273b1df4e939de0f540597c0931
missing blob dd4e97e22e159a585b20e21028f964827d5afa4e
missing tree 246f564d4cee53339b8a4244f3173b61caa518eb
dangling commit a01f5c1e5315dc837203d6dee00d3493be9c5db9

정말 안 좋아 보여요.를 할 때.git log | head는 이것을 이해합니다.

git log | head

error: Could not read 984c11abfc9c2839b386f29c574d9e03383fa589
fatal: Failed to traverse parents of commit 235ae1f48701d577d71ebd430344a159e5ba4881
commit 2fb0d2d0643b445440f01b164f11ee9ee71fca48
Author: christopher <christopher@christopher.christopher>
Date:   Wed Aug 7 15:51:42 2013 -0400

    finishing chapter 7

여기 있는 다른 질문들은 다음과 같은 것들을 살펴보라고 했습니다../git/refs/heads/master그것은 맨 레포고이고refs/heads/하지만 재지만입니다.refs/heads/master가 말하기를, 저장소에 있는 HEAD가.ref: refs/heads/master그래도.

packed-refs 것 같아요.

# pack-refs with: peeled
2fb0d2d0643b445440f01b164f11ee9ee71fca48 refs/heads/master

여전히 다른 질문들이 실행을 제안했습니다.git reflog실행해도 출력이 표시되지 않습니다.

그래서 저는 여기서 무엇을 해야 할지 정말 모르겠습니다.어떤 전략을 취해야 합니까?8월 7일 마지막 커밋으로 헤드를 재설정할 수 있습니까?

git log화면 출력의 맨 아래로 이동하면 다음과 같이 표시됩니다.

commit 996e03b949aea176238e3c7a8452700bbb987ac9
Author: christopher <christopher@christopher>
Date:   Wed Jul 3 23:00:44 2013 -0400

    many many changes
error: Could not read 984c11abfc9c2839b386f29c574d9e03383fa589
fatal: Failed to traverse parents of commit 235ae1f48701d577d71ebd430344a159e5ba4881

그것은 깃프룬이 작동하는 것을 방해하는 것처럼 보입니다.

Todd의 옵션( and Re-Initialization)에 있는 이하여 Todd를 할 수 ..git리모콘과 일치하는 것 (표준)${url} URL "URL"):

mv -v .git .git_old &&            # Remove old Git files
git init &&                       # Initialise new repository
git remote add origin "${url}" && # Link to old repository
git fetch &&                      # Get old history
# Note that some repositories use 'master' in place of 'main'. Change the following line if your remote uses 'master'.
git reset origin/main --mixed     # Force update to old history.

이렇게 하면 작업 트리는 그대로 유지되고 Git의 부기에만 영향을 미칩니다.

저는 또한 최근에 바로 이 목적을 위해 Bash 스크립트를 만들었습니다(부록 A). 이것은 이 작업에 대한 약간의 안전성을 포함합니다.

참고:

  • 이 있다면,이은 어떻게든 이고, 저소에하경있우는이스프하로세엉든로위것장사다다니입하용는음삭한제모해지을듈찾당은금해까책지결유은일한며만들것을 사용하는 것입니다.git submodule update --init(또는 저장소를 다시 복제하지만, 너무 극단적으로 보입니다.)
  • 이는 로컬 구성 설정에 따라 'main'과 'master' 중에서 올바른 선택을 결정하려고 하지만, 'main'을 기본 분기로 하는 시스템에서 'master'를 사용하는 저장소에서 사용할 경우 몇 가지 문제가 있을 수 있습니다.
  • 이 기능은 다음과 같습니다.wget작업을 수행하기 전에 URL에 도달할 수 있는지 확인합니다.은 사이트에 수 하는 데 적합한 , 수 없는 에는 이 을 사연수확있데아작최니이업은며선을, wget수다대수있음로다니습으로 대체할 수 .ping -c 1 "${url_base}"(linux),ping -n 1 "${url_base}" 또는 (윈도우즈), 는또curl -Is "${url_base}"

부록 A - 전체 스크립트

현재는 구식이지만, 요지로도 출판됩니다.

#!/bin/bash

# Usage: fix-git [REMOTE-URL]
#   Must be run from the root directory of the repository.
#   If a remote is not supplied, it will be read from .git/config
#
# For when you have a corrupted local repo, but a trusted remote.
# This script replaces all your history with that of the remote.
# If there is a .git, it is backed up as .git_old, removing the last backup.
# This does not affect your working tree.
#
# This does not currently work with submodules!
# This will abort if a suspected submodule is found.
# You will have to delete them first
# and re-clone them after (with `git submodule update --init`)
#
# Error codes:
# 1: If a URL is not supplied, and one cannot be read from .git/config
# 4: If the URL cannot be reached
# 5: If a Git submodule is detected


if [[ "$(find -name .git -not -path ./.git | wc -l)" -gt 0 ]] ;
then
    echo "It looks like this repo uses submodules" >&2
    echo "You will need to remove them before this script can safely execute" >&2
    echo "Then use \`git submodule update --init\` to re-clone them" >&2
    exit 5
fi

if [[ $# -ge 1 ]] ;
then
    url="$1"
else
    if ! url="$(git config --local --get remote.origin.url)" ;
    then
        echo "Unable to find remote 'origin': missing in '.git/config'" >&2
        exit 1
    fi
fi

if ! branch_default="$(git config --get init.defaultBranch)" ;
then
    # if the defaultBranch config option isn't present, then it's likely an old version of git that uses "master" by default
    branch_default="master"
fi

url_base="$(echo "${url}" | sed -E 's;^([^/]*://)?([^/]*)(/.*)?$;\2;')"
echo "Attempting to access ${url_base} before continuing"
if ! wget -p "${url_base}" -O /dev/null -q --dns-timeout=5 --connect-timeout=5 ;
then
    echo "Unable to reach ${url_base}: Aborting before any damage is done" >&2
    exit 4
fi

echo
echo "This operation will replace the local repo with the remote at:"
echo "${url}"
echo
echo "This will completely rewrite history,"
echo "but will leave your working tree intact"
echo -n "Are you sure? (y/N): "

read confirm
if ! [ -t 0 ] ; # i'm open in a pipe
then
    # print the piped input
    echo "${confirm}"
fi
if echo "${confirm}"|grep -Eq "[Yy]+[EeSs]*" ; # it looks like a yes
then
    if [[ -e .git ]] ;
    then
        # remove old backup
        rm -vrf .git_old | tail -n 1 &&
        # backup .git iff it exists
        mv -v .git .git_old
    fi &&
    git init &&
    git remote add origin "${url}" &&
    git config --local --get remote.origin.url | sed 's/^/Added remote origin at /' &&
    git fetch &&
    git reset "origin/${branch_default}" --mixed
else
    echo "Aborting without doing anything"
fi

TL;DR

Git은 당신이 생각하는 방식으로 역사를 저장하지 않습니다.상위 체인을 기준으로 런타임에 기록을 계산합니다.만약 여러분의 조상이 얼룩, 나무, 또는 약속이 없다면, 여러분은 여러분의 역사를 완전히 회복하지 못할 수도 있습니다.

백업에서 누락된 개체 복원

먼저 백업에서 누락된 항목을 복원합니다.를 들어,이 예를들백다업같음있확다인니는합지저장으로 합니다..git/objects/98/4c11abfc9c2839b386f29c574d9e03383fa589그렇다면 복원할 수 있습니다.

또한 커밋이 이미 채워져 있고 저장소 수술을 위해 느슨한 개체로 되돌리려는 경우 git-verify-packgit-unpack-object를 조사할 수도 있습니다.

외과적 절제

백업에서 누락된 항목을 바꿀 수 없는 경우 누락된 기록을 삭제할 수 있습니다.예를 들어 기록을 검사하거나 reflog를 통해 commit 984c11abfc9c2839b386f29c574d9e03383fa589의 상위 항목을 찾을 수 있습니다.손상되지 않은 것을 발견하면 다음을 수행합니다.

  1. Git 작업 디렉토리를 임시 디렉토리 어딘가에 복사합니다.
  2. 손상되지 않은 커밋을 하드 리셋합니다.
  3. 현재 파일을 Git 작업 트리에 다시 복사하지만 .git 폴더는 다시 복사하지 마십시오!
  4. 현재 작업 트리를 커밋하고, 누락된 모든 기록의 찌그러진 커밋으로 처리하기 위해 최선을 다합니다.

만약 그것이 효과가 있다면, 당신은 당연히 개입한 역사를 잃게 될 것입니다.이 시점에서 작업 기록 로그가 있는 경우 기록을 잘라내고 도달할 수 없는 모든 커밋 및 개체에 대한 기록을 다시 기록하는 것이 좋습니다.

전체 복원 및 재초기화

저장소가 여전히 손상된 경우 복원할 수 있는 손상되지 않은 백업 또는 복제본이 있을 수 있습니다.그렇지 않지만 현재 작업 디렉터리에 유효한 파일이 포함되어 있으면 언제든지 Git를 다시 초기화할 수 있습니다.예:

rm -rf .git
git init
git add .
git commit -m 'Re-initialize repository without old history.'

이 방법은 매우 어렵지만 저장소 기록을 복구할 수 없는 경우에만 사용할 수 있습니다.YMMV.

최근 우분투 18.04.3(바이오닉 비버)에서 Git 버전 2.7.1을 사용하여 비슷한 문제를 경험했습니다.제가 한 방법은 다음과 같습니다.

sudo apt install git-repair
git-repair  # Fix a broken Git repository
or
git-repair --force  # Force repair, even if data is lost
git fsck  # To verify it was fixed

대부분의 경우 복구 프로세스가 성공적이었습니다.

이 페이지에 설명된 수정 사항을 시도하기 전에 저장소의 복사본을 만들고 이 복사본에 대해서만 작업하는 것이 좋습니다.그런 다음 수정할 수 있으면 원본과 비교하여 복구 과정에서 파일이 손실되지 않았는지 확인합니다.

제게 효과가 있었던 또 다른 대안은 다음을 사용하여 Git 헤드와 인덱스를 이전 상태로 재설정하는 것이었습니다.

git reset --keep

Git GUI를 열고 각 "Stageed changes"를 선택한 후 "Unstage the changes"를 클릭하여 수동으로 동일한 작업을 수행할 수도 있습니다.모든 것이 준비되지 않은 경우 이제 데이터베이스를 압축하고 데이터베이스를 확인하고 커밋할 수 있습니다.

저도 다음과 같은 명령을 시도해 보았지만 실행되지 않았습니다.그러나 문제가 발생한 정확한 문제에 따라 다음과 같은 문제가 발생할 수 있습니다.

git reset --mixed
git fsck --full
git gc --auto
git prune --expire now
git reflog --all

마지막으로 동기화로 인해 Git 인덱스가 손상되는 문제(Dropbox, SpiderOak 또는 기타 클라우드 디스크에서 발생할 수 있음)를 방지하기 위해 다음을 수행할 수 있습니다.

  1. 다음을 사용하여 폴더를 단일 "번들" Git 파일로 변환합니다.git bundle create my_repo.git --all그러면 이전과 동일하게 작동해야 하지만, 모든 것이 단일 파일에 있기 때문에 더 이상 동기화로 인해 깃포가 손상될 위험이 없습니다.
  2. 즉각적인 동기화 사용 안 함: SpiderOak을 사용하면 변경 사항을 확인하는 일정을 "자동"(OS 알림으로 파일 변경을 모니터링하는 것이 가능함)으로 설정할 수 있습니다.이것은 좋지 않습니다. 변경을 수행하는 즉시 변경사항을 업로드하기 시작한 다음 변경사항을 다운로드하기 때문에 방금 수행한 최신 변경사항이 삭제될 수 있습니다.이 문제를 해결하는 방법은 변경 모니터링 지연을 5분 이상으로 설정하는 것입니다.또한 메모장++같은 응용 프로그램을 즉시 저장하는 문제도 해결할 수 있습니다.

다음은 @CodeGnome을 통해 첫 번째 솔루션을 자동화하여 백업에서 복원하는 스크립트(Bash)입니다(손상된 저장소의 최상위 수준에서 실행).백업을 완료할 필요는 없습니다. 누락된 개체만 있으면 됩니다.

git fsck 2>&1 | grep -e missing -e invalid | awk '{print $NF}' | sort -u |
    while read entry; do
        mkdir -p .git/objects/${entry:0:2}
        cp ${BACKUP}/objects/${entry:0:2}/${entry:2} .git/objects/${entry:0:2}/${entry:2}
    done

원격이 구성되어 있고 푸시되지 않은 일부 코드가 손실되거나 손실되지 않을 경우 다음 작업을 수행할 수 있습니다.

git fetch && git reset --hard

0바이트의 객체 파일을 제거하고 원격에서 다시 가져오려고 시도했는데, 작동했습니다.

find . -type f -size 0 -exec mv {} /tmp \;
git fetch

원격에서 누락된 개체를 가져와 전체 저장소를 다시 초기화하지 않고 작업을 계속할 수 있었습니다.

git-repair)sudo apt install git-repair몇인 명령어를 했습니다.

  1. 손상된 리포지토리의 백업 복사본을 만듭니다.

  2. 손상된 참조 삭제:
    find .git/refs -size 0 -delete -print

  3. 원격에서 리포지토리 복구:
    git-repair --force

  4. 매달린 커밋 정리:
    git gc --prune=now

  5. 원격에서 최신 상태 가져오기:
    git fetch

선택적으로 마스터로 전환하고 오리진/마스터로 재설정합니다.
git checkout master
git reset --hard origin/master

gitfsck를 사용하여 확인:
git fsck

절박한 경우 다음을 시도할 수 있습니다.

git clone ssh://me@my.git.server/path/to/project destination --depth=1

데이터는 얻을 수 있지만 기록은 잃게 됩니다.저는 제 보고서에 시행착오를 겪었고,--depth=10효과는 있었지만,--depth=50나는 실패했습니다.

나의 경우, 나는 이미 내 PC에 있는 소스 코드로 저장소를 만들고 있었고 그 오류가 나타났습니다..git 폴더를 삭제하고 모든 것을 다시 해보니 작동했습니다 :)

저는 같은 문제에 직면하고 있었기 때문에 ".git" 폴더를 백업 버전으로 교체했는데 .gitconfig 파일이 손상되어 여전히 작동하지 않았습니다.내 노트북의 BSoD가 그것을 손상시켰습니다.나는 그것을 다음 코드로 교체했고 소스 트리는 나의 모든 저장소를 복원했습니다.

[user]
name = *your username*
email = *your email address*
[core]
autocrlf = true
excludesfile = C:\\Users\\*user name*\\Documents\\gitignore_global.txt

이것이 누군가에게 도움이 될지는 모르겠지만, 이것은 저에게 효과가 있었던 또 다른 해결책일 뿐입니다.

다른 폴더에 리포지토리의 새 복제본을 만들고 해당 폴더에서 블롭을 가져왔습니다.

원래 실행된 저장소에서:

git reset --hard origin/main   # reset index to a known good state
git unpack-objects < /path/to/new/clone/.git/objects/pack/<hash>.pack
git fsck --full | grep -v dangling

그 후에는 모든 것이 괜찮았습니다 :)

위의 것이 작동하지 않는다면, 체크가 비활성화된 git를 수정하는 것이 나에게 매우 효과적이었다는 보고서가 있습니다.저는 그냥 "회복할 수 없는" 레포를 고쳤습니다.

본질:

객체 git 진내개체이부내(()).git/objects형식으로 입니다.는 이진 데이터 형식으로 함께 포장된 gzip-ped blob입니다.대부분의 경우 이러한 파일이 손상된 경우 Git에서 지원할 경우 매우 잘 작동하는 부분 복구를 얻을 수 있습니다.다양한 검사(대부분: 개체 파일을 열 수 없거나 BLOB의 압축을 풀면 오류가 발생함)가 발생하여 처리가 중지되고 치명적인 오류가 발생합니다.

적어도 소스에서 Git를 패치하고 다시 컴파일할 수 있는 수준에서는 약간의 C 기술이 필요합니다.수정해야 하는 것은 항상 동일합니다. git someone은 치명적인 오류와 함께 처리를 중지하므로 이를 주석 처리하고 빈 모의로 대체합니다.에는 그후에, a./your/patched/git gc --aggressive --prune=now(일반적인 슈퍼 어그레시브 리패커)는 수정해야 할 사항을 수정합니다.예를 들어 아래 패치는 일부 개체 파일이 손상된 Git repo를 수정할 수 있습니다.물론 복구는 부분적일 뿐입니다. 손상된 개체의 파일은 소급하여 손실됩니다.

이것이 Git 개발이 그러한 사소한, 그러나 매우 유용한 개선을 구현하지 않는 이유일 수 있습니다.필요한 패치 사이즈는 100줄 이하가 될 것 같습니다.

아이디어를 더욱 발전시키면 이러한 손상된 저장소를 복구할 수 있는 깃포크도 만들 수 있을 것입니다.

diff -urNw orig/sha1-file.c patched/sha1-file.c
--- orig/sha1-file.c   2021-03-08 21:36:01.000000000 +0100
+++ patched/sha1-file.c 2021-08-19 18:32:44.019115545 +0200
@@ -1285,8 +1285,16 @@
        else if (stream->avail_in)
                error(_("garbage at end of loose object '%s'"),
                      oid_to_hex(oid));
+
+  error("error ignored");
+
+  /*
        free(buf);
        return NULL;
+  */
+
+  status = Z_OK;
+  return buf;
 }
 
 /*
@@ -1656,7 +1664,7 @@
                    oid_to_hex(repl), oid_to_hex(oid));
 
        if (!stat_loose_object(r, repl, &st, &path))
-               die(_("loose object %s (stored in %s) is corrupt"),
+               error(_("loose object %s (stored in %s) is corrupt"),
                    oid_to_hex(repl), path);
 
        if ((p = has_packed_and_bad(r, repl->hash)) != NULL)
@@ -1664,7 +1672,9 @@
                    oid_to_hex(repl), p->pack_name);
        obj_read_unlock();
 
-       return NULL;
+  errno = 0;
+  error("error ignored");
+       return strdup("");
 }
 
 void *read_object_with_reference(struct repository *r,
@@ -2473,10 +2483,12 @@
        }
        git_inflate_end(stream);
 
+  /*
        if (status != Z_STREAM_END) {
                error(_("corrupt loose object '%s'"), oid_to_hex(expected_oid));
                return -1;
-       }
+       }*/
+
        if (stream->avail_in) {
                error(_("garbage at end of loose object '%s'"),
                      oid_to_hex(expected_oid));

현재 프로젝트에 변경 사항이 있지만 프로젝트를 잃지 않으려면 현재 프로젝트를 다른 곳으로 이동하고 GitHub에서 이 폴더로 프로젝트를 복제한 후 변경하고 다시 커밋을 시도하는 빠른 방법은 다음과 같습니다.

또는 리포지토리를 삭제하고 다시 복제합니다.그것은 나에게 효과가 있었다.

위의 조이 휴일의 멋진 답변 아래 댓글로 추가하고 싶었지만, 현재 제가 담당자가 부족해서 여기에 추가하고 그녀의 작품에 대한 공로를 인정해야 합니다 :P

만약 당신이 Poshgit를 사용하고 있고 특별히 게으르다고 느낀다면, 당신은 다음을 사용하여 당신의 Git 구성에서 당신의 URL을 자동으로 추출하고 더 쉽게 작업할 수 있습니다.사용자의 얼굴에 폭발이 발생할 경우를 대비하여 먼저 로컬 저장소에서 이를 테스트/백업하는 것에 대해 표준 주의 사항이 적용됩니다.

$config = get-content .git\config
$url = $config -match "    url = (?<content>.*)"
$url = $url.trim().Substring(6)
$url

move-item -v .git .git_old;
git init;
git remote add origin "$url";
git fetch;
git reset origin/master --mixed

이 명령은 나에게 효과가 있었습니다.

git reset --mixed

언급URL : https://stackoverflow.com/questions/18678853/how-can-i-fix-a-corrupted-git-repository

반응형