0
0

More than 1 year has passed since last update.

Gitで誤って異なるユーザで初回プッシュしてしまった時の対処方法

Posted at

課題

1

Gitで異なるユーザで初回プッシュしてしまったので、正しいユーザでプッシュし直したい

2

ググってみるとgit push -f origin HEAD^を実行しろ、とあるのでやってみるとエラーとなる。

$ git push -f origin HEAD^:main
error: src refspec HEAD^ does not match any
error: failed to push some refs to 'github.com:hoge.git'

対処法

以下コマンドを実行する

$ git update-ref -d HEAD

git logをするとログがなくなっている状態となる

git log
fatal: your current branch 'main' does not have any commits yet

ユーザ設定変更する

git config user.name "hoge"
git config user.email "hoge@hoge.com"

変更内容を確認する

$ cat .git/config

...

[user]
        name = hoge
        email = hoge@hoge.com

コミットする

$ git commit -m "first commit"

git logしてみる
Author部分の名前とメールアドレスが変更後のものになっていることを確認

$ git log

プッシュする

$ git push -f origin main

参考

0
0
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
0