LoginSignup
16

More than 5 years have passed since last update.

Gitでベアリポジトリにforce pushが出来ない場合

Last updated at Posted at 2014-12-03

現象

間違えたcommitをリモートリポジトリのmasterにpushしてしまい、戻そうと思ったがなぜかforce pushでエラーになってしまった。

$ git reset --hard HEAD^
$ git push -f origin master
略
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '/hoge/foo/bar'
略

原因

リモートリポジトリ内のconfigファイルに以下の設定が入っていたため。

[receive]
    denyNonFastforwards = true

解決策

1.リモートリポジトリのconfigを以下のように編集する。

[receive]
    denyNonFastforwards = false

2.force pushする。

$ git push -f origin master

解決!

まとめ

  • ベアリポジトリの初期設定はファストフォワード以外を禁止しているため、歴史を戻すことが出来なかった。
  • Gitは使い始めて間もないので実は常識だったりする?
  • githubのリポジトリでは歴史を戻すfource pushが出来るため、nonFastforwardsの設定はfalseになっているのだろうか。

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
16