컴퓨터가 죽은 후 Git 저장소가 손상됨
내 컴퓨터가 죽었고 이제 내 git 저장소 중 하나가 손상되었습니다. 결제 마스터를 시도하면 다음과 같이 알려줍니다.
warning: ignoring broken ref refs/heads/master.
error: Your local changes to the following files would be overwritten by checkout:
com.vainolo.jdraw2d.releng.p2/pom.xml
Please, commit your changes or stash them before you can switch branches.
Aborting
실행 git stash
하면 다음을 얻습니다.
fatal: bad revision 'HEAD'
fatal: bad revision 'HEAD'
fatal: Needed a single revision
You do not have the initial commit yet
그래서 내가 무엇을 할 수 있니?
업데이트 출력 git reflog
:
fatal: bad default revision 'HEAD'
별로 유망하지 않은 ... 결과 git fsck
:
error: Invalid HEAD
Checking object directories: 100% (256/256), done.
error: unable to unpack 59551f96b4e87a1c14293c19eb548ce6fa1f196f header
error: inflateEnd: stream consistency error (no message)
fatal: loose object 59551f96b4e87a1c14293c19eb548ce6fa1f196f (stored in .git/objects/59/551f96b4e87a1c14293c19eb548ce6fa1f196f) is corrupt
나는 다음을 통해 회복했습니다.
rm .git/refs/remotes/origin/HEAD
git fetch --all
손상된 git 저장소 복구에 제안 된 단계에 따라 시작하십시오 .
.git/refs
여전히 유용한 것이 있는지 확인- 마지막에
git reflog
있었던.git/logs/refs/heads/master
브랜치 의 내용을 확인 하고 실패 - 실행
git fsck
, 잠재적으로--unreachable
또는--lost-found
이를 통해 master
ref가 무엇인지 파악하여 이를 복원 할 수 있습니다 (예 : 올바른 SHA1을 .git/refs/heads/master
.
해당 커밋에 포함 된 개체가 실제로 손상된 경우 HEAD
불행히도 커밋을 복원 할 수 없습니다 . 작업 트리 및 / 또는 인덱스가 손상되지 git reset --soft
않았다고 가정 git reset
하면 이전 커밋을 시도 (또는 실패 ) 한 다음 커밋을 다시 수행 할 수 있습니다. 작업 트리 sa git checkout -f
또는 git reset --hard
.
Windows 8.1에서 블루 스크린으로 인해 비슷한 문제가 발생했습니다.
이 위치에 파일이 있습니다 ...
C:\www\<project>\.git\refs\remotes\origin\<problem-branch>
그리고이 폴더의 다른 분기 파일에는 내부에 긴 문자열이있는 반면 비어있었습니다.
NB 변경 / 커밋이 없습니다.
<problem-branch>
파일을 백업했습니다- 파일을 삭제했습니다.
git fetch --all
다시 가지를 얻으려면
그런 다음 탭 자동 완성이 다시 작동하기 시작했습니다.
수정 된 파일이 많지 않은 경우이 문제를 해결하는 가장 편리한 방법은 다음과 같습니다.
- 리포지토리에서 수정 한 파일 백업
- 기존 저장소 제거
- 서버에서 다시 복제
- 1 단계의 파일을 저장소에 붙여넣고
git commit -a
git \ refs \ heads 디렉토리에서 마스터 파일을 삭제하여이 문제를 해결했습니다.
계산 된 동결 및 충돌 후 git 분기가 다음 메시지와 함께 손상되었습니다 git fatal: your current branch appears to be broken
. 나는 아무것도 할 수 없었다.
그 후 git fsck
분기에 error: Invalid HEAD
. refs/heads/<branch>
했다 invalid sha1 pointer
.
여기의 옵션을 .git/refs/heads/<branch>
따를 때 메모장 ++ 편집기에서 열었고 각 sha1 문자는 NUL
.
다행히 분기를 원격 상태로 재설정하기 만하면되었으며 이는 bitbucket repo에있었습니다. 원격 저장소의 끝에서 sha1을 가져 .git/refs/heads/<branch>
와서 저장 한 다음을 수행 git reset --hard HEAD
하고 모든 작업을 정상으로 되돌 렸습니다.
I was idiot enough to forget to push and my computer crashed while performing a commit. I could recover everything but the last commit though by opening .git/logs/refs/heads/
This file contains all commits (with their SHAs) to the branch, what I did to recover was:
- Back up latest changes to a temp folder
- move to a "clean slate"
git checkout master
git reset --hard
- checkout the second to last commit in the log
- create a branch from this detached head
- PUSH
- Restore the latest changes
- Commit again
So even when you make a dumb mistake, you're not immediately taken back by a whole day of work with git :)
I know it's a too-late response, but I was getting this error because I did not have an origin/head
. You can find this out by running git branch -r
. If you do not see your origin/head
pointing to a remote origin, you can set this by running git remote set-head origin {{your branch name}}
.
Now run git branch -r
again, and you should see something like this: origin/HEAD -> origin/develop
I hope this helps anyone else who's running into this issue.
My computer crashed two times and a result, my git repository got broken locally. I could not pull my changes, it asked to set remote origin but it did not work in gitKraken.
On my command prompt, I was getting this error
I knew that my references are broken and needs to be fixed. What I had to do is, to git bash (In SourceTree click on "terminal"). Then navigate to references folder like this
cd .git
cd refs
cd remotes
cd origin
there will be a file name master
there, use ls
to see what is in the directory. Then simply delete it using rm master
bam, the corrupted file is gone. Now if you issue git branch command -a, it would output this
$ git branch -a
* master
remotes/origin/master (this in red color -scary :) )
Then issue this command, and it will fix your references
$ git remote set-head origin master
To sum it up, if you would try to pull the remote, it should show blank remote name which has been fixed.
I had the same issue but no luck, couldn't figure out the problem. I took my repo to a side, re-cloned the one from server and tried to merge between them. Of course it shown a lot of files not related to my branch, but help to isolate the files required.
Check if MSWindows created desktop.ini files that are bothhering the git? it does for me. Once I delete them all in the subfolders of the .git directory then it works.
I had this same problem when Android Studio terminated suddenly (due to loss of power to computer).
I solved it by copying the contents of my C:\Users\myusername\AndroidStudioProjects\MyBrokenApp\.git\refs\heads\master
file to my C:\Users\myusername\AndroidStudioProjects\MyBrokenApp\.git\refs\remotes\origin\master
file.
(Previously, I'd also turned on the 'Force Push' option in Android Studio, but I don't think this was a necessary step.)
Note:
I found this solution by comparing the content of the files in my C:\Users\myusername\AndroidStudioProjects\MyBrokenApp\.git\
directory (inc. subdirectories) to the corresponding files of those in another healthy project - e.g., C:\Users\myusername\AndroidStudioProjects\MyHealthyApp\.git\
.
You may have a different file that is corrupt, but by comparing with another healthy project, you should be able to quickly spot what is wrong.
If you don't have another healthy project that has git configured, it may be worth creating a simple one in the same way that you created your broken project so can investigate, compare and fix, etc.
PS - My error message (edited) was: warning: ignoring broken refs/remotes/origin/master.fatal bad revision 'refs/remotes/origin/master..refs/heads/master' during executing git -c core.quotepath=false log refs/remotes/origin/master..refs/heads/master --pretty=format --encoding=UTF-8 -M --name-status -c --
I could not checkout my master branch due to the cannot lock ref error. I ended up deleting: .git/refs/remotes/origin/HEAD
.git/refs/remotes/origin/master
and calling this git command:
git fetch --all
Forgive me if I would repeat after someone (I haven't read all feedback). In my opinion, the simplest way to solve the problem is to copy project without .git and .idea, clean it up, clone from git, delete everything except above directories and then paste previous copy to newly created repo with .git and .idea. Hope it does make sense.
참고URL : https://stackoverflow.com/questions/15317072/git-repository-broken-after-computer-died
'developer tip' 카테고리의 다른 글
Div 오버레이를 전체 페이지 (뷰포트뿐만 아니라)로 만드시겠습니까? (0) | 2020.09.13 |
---|---|
로거 래퍼 모범 사례 (0) | 2020.09.13 |
Visual Studio Community Edition 2015 및 2017에서 누락 된 CodeLens 참조 수 (0) | 2020.09.13 |
C에서 16 진수 문자 인쇄 (0) | 2020.09.13 |
Python 3 바이트 문자열 변수를 일반 문자열로 어떻게 변환합니까? (0) | 2020.09.13 |