課題
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
参考