0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

「reference broken」を解消してGitHubから変更をPullする

Posted at

TL;DL

サブPCで編集した内容をGitHubにアップロードしたあと、メインPCで変更内容をPullしようと思ったら、
「reference broken」とかいうエラーになって変更を反映できなくなってしまった。

この問題について解決方法を記載する。

現象

(notisumma) D:\work\venv\notisumma>git pull origin master
From github.com:xxxxxx/notisumma
 * branch            master     -> FETCH_HEAD
error: cannot lock ref 'refs/remotes/origin/master': unable to resolve reference 'refs/remotes/origin/master': reference broken
 ! [new branch]      master     -> origin/master  (unable to update local ref)

原因

正直原因は不明。
gitへのpush途中でプロセスが切れるような現象が発生した場合にreferenceファイル('refs/remotes/origin/master')が
破損して発生することがあるらしい。

今回はそんな事象が発生した覚えはないが、サブPCで編集したファイルをアップロードする際、
コンソールからGitコマンドでpushしたのではなく、GitHubのリポジトリページにドラッグ&ドロップして
アップロードしたのが原因なのかと思う。(検証はしていない)

解決方法

1.git gc --auto

Gitは時々 “auto gc” と呼ばれるコマンドを自動的に実行します。 大抵の場合、このコマンドは何もしません。 ですが、緩いオブジェクト(packfileの中に入っていないオブジェクト)やpackfileがあまりに多い場合は、Gitは完全な(full-fledged)git gc コマンドを起動します。 “gc” はガベージコレクト(garbage collect)を意味します。このコマンドは幾つものことを行います。すべての緩いオブジェクトを集めてpackfileに入れ、複数のpackfileをひとつの大きなpackfileに統合し、さらにどのコミットからも到達が不可能かつ数ヶ月間更新がないオブジェクトを削除します。

詳しくは調べてないが、このコマンドを実行することで今回問題が発生している'refs'フォルダ内がガーベジコレクトされて
問題が解決することがあるらしい。

結果

解消されなかった。
発生する現象自体変化なし

2.問題のファイルを手動で削除する。

解決するコマンドがわからないなら、問題が発生するファイルを力ずくで消してしまおう。(昭和生まれ思考)
スクリーンショット (2).png

結果

正常にpullすることができた。

(notisumma) D:\work\venv\notisumma>git pull origin master
From github.com:xxxxx/notisumma
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
Updating 1916fff..0f77dfa
Fast-forward
 sample/sample.zip | Bin 0 -> 803530 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 sample/sample.zip

まとめ

手動作業最強。

冗談はさておき、普段業務でGitを使うことはないので、昔勉強したコマンドとかTipsをほとんど忘れてる。
やっぱ日々使ってないとだめだと痛感した。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?