IT,프로그래밍/Git

[Git] Sourcetree fetch 오류 (reference broken)

증상

 

Sourcetree 에서 fetch 를 하던중 오류 발생했다.

unable to resolve reference 'refs/remotes/origin/master': reference broken

이전에도 다른 브랜치들의 최신화를 위해 패치를 진행할때 저런 오류가나서 고치지 못하고

local 의 폴더를 날리고 새로 clone 을 받았는데 이번에도 같은 경우가 생긴것이다.

 

해결법

이런 방법으로 반복할수는 없어서 검색을 하니 stackoverflow 에서 이 글 을 발견할수 있었다.

가장 추천을 많이 받은 방법은

$ git gc --prune=now
$ git remote prune origin

 

man git-gc(1):

git-gc - Cleanup unnecessary files and optimize the local repository

git gc [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune]

       Runs a number of housekeeping tasks within the current repository, such as compressing file revisions
       (to reduce disk space and increase performance) and removing unreachable objects which may have been
       created from prior invocations of git add.

       Users are encouraged to run this task on a regular basis within each repository to maintain good disk
       space utilization and good operating performance.

 

man git-remote(1):

git-remote - manage set of tracked repositories

git remote prune [-n | --dry-run] <name>

           Deletes all stale remote-tracking branches under <name>. These stale branches have already been
           removed from the remote repository referenced by <name>, but are still locally available in
           "remotes/<name>".        

 

나의 경우는 잘되지 않았다.

 

그래서 좀더 심플한 2번쨰로 추천을 많이 받은

rm .git/refs/remotes/origin/master
git fetch

방법을 해주니 정상적으로 잘 fetch 에 성공 되었다!

 

 

원인

원인을 찾던중 한 글을 발견할수 있었는데 내용은 아래와 같다

  1. Possible root cause

On my system (Windows 7 64-bit), when a BSOD happens, some of the stored reference files (most likely currently opened/being written into when BSOD happened) are overwritten with NULL characters (ASCII 0).

As others mentioned, to fix it, it's enough to just delete those invalid reference files and re-fetch or re-pull the repository.

Example

Error: cannot lock ref 'refs/remotes/origin/some/branch': unable to resolve reference 'refs/remotes/origin/some/branch': reference broken

Solution: delete the file %repo_root%/.git/refs/remotes/origin/some/branch

 

2.

Troubleshooting method: With SourceTree on Windows Servers, you may try to run it as an Administrator. That fixes my problem of "unable to update local ref" on Atlassian Source Tree 2.1.2.5 on a Windows Server 2012 R2 in domain.

 

If you can too replicate this situation, it proves that the problem is caused by permission issue. It's better to drill down and find the root cause - probably some particular files are owned by other users and such - otherwise there's an unwelcome side-effect: you'll have to run SourceTree as Administrator for the rest of eternity.

 

해석을 해보자면 소스트리를 윈도우 OS 상에서 돌리게 되면 생기는 오류 같다.

 

하지만 내가 생각한 근본적인 이유는

리모트 브랜치와 내 로컬 브랜치가 있는데 이 ref 부분에 충돌이 나는것이 원인인것 같다

만일 틀린 점이 있다면 댓글로 달아주시면 감사하겠습니다.