問題発生 / 「.git」ディレクトリ毎移動してみたが失敗 / イレギュラーな作業履歴

カテゴリー: Git BASH  閲覧数:329 配信日:2022-10-20 20:27


問題発生


P25をP48のリポジトリへ反映させていた

以下、イレギュラーな対応

「.git」ディレクトリ毎コピーしてみたが失敗


P25ディレクトリ直下に作成された「.git」ディレクトリを、P48ディレクトリ直下へ移動後、「$ git add -A」コマンドを実行したが、エラーを解決できなかった。

イレギュラーな作業履歴


「.git」ディレクトリ削除
コピー配置してみた「.git」ディレクトリを手動削除。

ディレクトリ移動
$ cd /L/1_Hp/0_sakura/2018server/var/www/html/p-48

作業ディレクトリ内の変更をステージングエリアへ追加してコミット候補にする
$ git add -A
warning: adding embedded git repository: site-rank.xxxx.xxxxx

今回配置したディレクトリ内(直下とは異なるパス)に別リポジトリがあったようなので、「.git」ディレクトリを削除。

再度、作業ディレクトリ内の変更をステージングエリアへ追加してコミット候補にする
$ git add -A

ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示)
$ git remote -v
origin  git@github.com:GitHubユーザー名/P48-First-Ranking-Service.git (fetch)
origin  git@github.com:GitHubユーザー名/P48-First-Ranking-Service.git (push)


インデックスに追加されたファイルをコミットする(コミットメッセージも指定する)
$ git commit -m "first commit"
[main (root-commit) ccd0a75] first commit
154 files changed, 71890 insertions(+)


ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる。
$ git push origin main
To github.com:GitHubユーザー名/P48-First-Ranking-Service.git
! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'github.com:GitHubユーザー名/P48-First-Ranking-Service.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる。※既存リモートリポジトリ履歴を全消去
既存リモートリポジトリにあるコミット履歴および内容は全消去。今回の場合は、誤って反映されたP25コミット履歴および内容が全消去された。
$ git push -f origin main
Enumerating objects: 146, done.
Counting objects: 100% (146/146), done.
Delta compression using up to 8 threads
Compressing objects: 100% (142/142), done.
Writing objects: 100% (146/146), 660.01 KiB | 2.16 MiB/s, done.
Total 146 (delta 38), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (38/38), done.
To github.com:GitHubユーザー名/P48-First-Ranking-Service.git
+ 839752f...ccd0a75 main -> main (forced update)


週間人気ページランキング / 7-30 → 8-5
順位 ページタイトル抜粋 アクセス数
1 開発 0 17
2 「Twitter Developers」でアプリケーションを新規作成するためには? SMS認証用コードを確認可能な電話番号の登録が必要 | Twitter Developer(Twitter) 4
2 「Twitter API」経由でツイートを無料取得することはできません。 | Twitter API (Twitter) 4
2 Twitter 目次 | Twitter Developer(Twitter) 4
2 Twitter API v1.1 | Twitter Developer(Twitter) 4
2 Git BASH 作業履歴 2022/10/21 / P28 site-ranking(4Th-Ranking-Service) / 他の「.git」ディレクトリが存在した状態のまま下記gitコマンドを実行したため、意図せず「submodule」化されてしまった例 | Git BASH(Git) 4
2 Twitter アカウント管理 | Twitter Developer(Twitter) 4
2 Bootstrap(デザイン) カテゴリー 4
3 Twitter Developer Labs | Twitter Developer(Twitter) 3
3 埋め込みツイート | Twitter Developer(Twitter) 3
3 マッチングサービス | Webサービスビジネス 3
3 「Git Bash」→「GitHub」気づき 2022 | GitHub(Git) 3
3 「Twitter Developers」でApp作成 | Twitter Developer(Twitter) 3
3 「Windows10」へ「gitfor windows VERSION 2.22.0」をインストール | GitHub(Git) 3
3 authorize VS authenticate VS アプリケーションのみの認証 | Twitter Developer(Twitter) 3
3 個人事業主 | Webサービスビジネス 3
3 同じ携帯電話番号でも、複数の「Twitter Developers」アカウントを作成可能 | Twitter Developer(Twitter) 3
3 Twitter 複数アカウントでPOSTしたい | Twitter Developer(Twitter) 3
3 fatal: remote error: is not a valid repository name | Git BASH(Git) 3
3 本 | ブックマーク 3
2026/8/6 5:05 更新
指定期間人気ページランキング / 2020-5-27 → 2026-8-5
順位 ページタイトル抜粋 アクセス数
1 GitHubリモートリポジトリ名には日本語を使用できない。使用すると、ハイフンへ自動置換されてしまう | GitHub(Git) 1083
2 fatal: remote error: is not a valid repository name | Git BASH(Git) 754
3 開発 0 714
4 Twitter アカウント管理 | Twitter Developer(Twitter) 629
5 Twitter API | Twitter API (Twitter) 605
6 動画対応 | プログラミング 598
7 「Twitterデータ」対応 | Twitter Developer(Twitter) 569
8 Windows10で使用できるGitクライアント | GitHub(Git) 471
9 本 | ブックマーク 463
10 Webサービス | ブックマーク 435
11 マッチングサービス | Webサービスビジネス 410
12 同じ携帯電話番号でも、複数の「Twitter Developers」アカウントを作成可能 | Twitter Developer(Twitter) 374
13 TwitterOAuth では、画像URL を指定した画像投稿は出来ない(と思う)。ライブラリを使用しなければ出来るから、Twitter API の制限ではない(と思われる)  | Twitter 334
14 技術書籍 | プログラミング 308
14 teratailでは質問しない | プログラミング 308
15 気になった動画 | ブックマーク 300
16 埋め込みツイート | Twitter Developer(Twitter) 278
17 個人事業主 | Webサービスビジネス 256
18 ログイン 251
19 Twitter 電話番号の問題 | Twitter Developer(Twitter) 248
2026/8/6 5:05 更新