Git BASH 作業履歴 2022/10/20 / P25 manga-user-ranking(Second-Ranking-Service) / 「Add a README」後「git merge --allow-unrelated-histories origin/main」実行して、「README」もコミット履歴に含める

GitGit BASH

目次一覧

 状態:-  閲覧数:382  投稿日:2022-10-20  更新日:2022-10-20
0.GitHub リモートリポジトリ作成 / 1.「Git BASH」起動 / 2.ディレクトリ移動

3.作業ディレクトリ内へ、Gitの(空の)ローカルリポジトリを作成する / 4.作業ディレクトリ内の変更をステージングエリアへ追加してコミット候補にする / 5.インデックスに追加されたファイルをコミットする(コミットメッセージも指定する)

ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示) / 6.ローカルリポジトリに、リモートリポジトリを設定する / 7ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示)

ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる → 失敗 / 7.共通の祖先を持たないブランチ同士をマージする / 8.ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる

9.ダンプデータとスクリーンキャプチャを配置 / 10.作業ディレクトリ内の変更をステージングエリアへ追加してコミット候補にする / 11.ダンプデータとスクリーンキャプチャを配置

12.ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる / 迷走作業失敗履歴


0.GitHub リモートリポジトリ作成 / 1.「Git BASH」起動 / 2.ディレクトリ移動

 閲覧数:153 投稿日:2022-10-20 更新日:2022-10-20

0.GitHub リモートリポジトリ作成


GitHub の GUI 経由でリモートリポジトリを作成
P25-Second-Ranking-Servic
Private

その際「Add a README file」にチェックを入れる。
※この操作は(最初のコミット(Initial commit)となるため、とても)重要。後の操作に大きく関わってくる。
※後から容易に追加できるため、GitHubに慣れるまではこの時点でチェックを入れないほうが無難だと思われる。

1.「Git BASH」起動


L:\9.soft\Git\git-bash.exe

2.ディレクトリ移動


Lドライブへ移動
$  cd /L

同じドライブ内を移動
「L:\1_Hp\0_sakura\2018server\var\www\html\p-25」へ移動する。
※コマンドは、バックスラッシュではなくスラッシュ

$ cd /L/1_Hp/0_sakura/2018server/var/www/html/p-25


3.作業ディレクトリ内へ、Gitの(空の)ローカルリポジトリを作成する / 4.作業ディレクトリ内の変更をステージングエリアへ追加してコミット候補にする / 5.インデックスに追加されたファイルをコミットする(コミットメッセージも指定する)

 閲覧数:114 投稿日:2022-10-20 更新日:2022-10-20

3.作業ディレクトリ内へ、Gitの(空の)ローカルリポジトリを作成する


$ git init
Initialized empty Git repository in L:/1_Hp/0_sakura/2018server/var/www/html/p-25/.git/


4.作業ディレクトリ内の変更をステージングエリアへ追加してコミット候補にする


git add -A (git add --all)
変更があったすべてのファイルが、ステージングエリアへされる
変更されたファイル、削除されたファイル、新しく作られたファイル、すべてがステージングエリアへされる
$ git add -A

5.インデックスに追加されたファイルをコミットする(コミットメッセージも指定する)


$ git commit -m "first commit"
[main (root-commit) 260333c] first commit
591 files changed, 56849 insertions(+)
create mode 100644 0webapp/LICENSE
create mode 100644 0webapp/MiniBlogApplication.php


ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示) / 6.ローカルリポジトリに、リモートリポジトリを設定する / 7ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示)

 閲覧数:120 投稿日:2022-10-20 更新日:2022-10-20

ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示)


$ git remote -v
設定をまだ行っていないため、何も表示されない

6.ローカルリポジトリに、リモートリポジトリを設定する


※リモートリポジトリは、GitHub の GUI 経由で事前作成しておく必要がある。今回事前に作成したリモートリポジトリ名は「P25-Second-Ranking-Service」。
$ git remote add origin git@github.com:GitHubユーザー名/P25-Second-Ranking-Service.git

ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示)


$ git remote -v
origin  git@github.com:GitHubユーザー名/P25-Second-Ranking-Service.git (fetch)
origin  git@github.com:GitHubユーザー名/P25-Second-Ranking-Service.git (push)


ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる → 失敗 / 7.共通の祖先を持たないブランチ同士をマージする / 8.ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる

 閲覧数:97 投稿日:2022-10-20 更新日:2022-10-20

ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる → 失敗


$ git push origin main
To github.com:GitHubユーザー名/P25-Second-Ranking-Service.git
! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'github.com:GitHubユーザー名/P25-Second-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.

GitHub上でリポジトリを作成したタイミングで、README.mdがコミットされているのに、それをローカルリポジトリに取り込まずに、ローカルのソースをコミットしてしまったのが原因と思われる。
結果、それぞれが別ヒストリとなり、mergeエラーになった
初めてGitHubリポジトリにpushしたらrejectedエラーになったときの対応メモ

7.共通の祖先を持たないブランチ同士をマージする


ローカルリポジトリにリモートリポジトリの内容(今回はREADME.txtのみ)がmergeされる。
$ git merge --allow-unrelated-histories origin/main
Merge made by the 'ort' strategy.
README.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 README.md


8.ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる


$ git push origin main
Enumerating objects: 627, done.
Counting objects: 100% (627/627), done.
Delta compression using up to 8 threads
Compressing objects: 100% (616/616), done.
Writing objects: 100% (626/626), 22.08 MiB | 2.75 MiB/s, done.
Total 626 (delta 66), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (66/66), done.
To github.com:GitHubユーザー名/P25-Second-Ranking-Service.git
  40aecc9..08bd5d3  main -> main


9.ダンプデータとスクリーンキャプチャを配置 / 10.作業ディレクトリ内の変更をステージングエリアへ追加してコミット候補にする / 11.ダンプデータとスクリーンキャプチャを配置

 閲覧数:116 投稿日:2022-10-20 更新日:2022-10-20

9.ダンプデータとスクリーンキャプチャを配置



10.作業ディレクトリ内の変更をステージングエリアへ追加してコミット候補にする


$ git add -A

11.ダンプデータとスクリーンキャプチャを配置


$ git commit -m "SQL dumpdata,Screen capture"
[main aa8864c] SQL dumpdata,Screen capture
3 files changed, 34486 insertions(+)
create mode 100644 ibj_mangauser.sql


12.ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる / 迷走作業失敗履歴

 閲覧数:123 投稿日:2022-10-20 更新日:2022-10-20

ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる



$ git push origin main
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 414.44 KiB | 6.19 MiB/s, done.
Total 5 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To github.com:GitHubユーザー名/P25-Second-Ranking-Service.git
  08bd5d3..aa8864c  main -> main



迷走作業失敗履歴


$ git push origin main
To github.com:GitHubユーザー名/P25-Second-Ranking-Service.git
! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'github.com:GitHubユーザー名/P25-Second-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.


$ git pull origin main
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 640 bytes | 5.00 KiB/s, done.
From github.com:GitHubユーザー名/P25-Second-Ranking-Service
* branch            main       -> FETCH_HEAD
* [new branch]      main       -> origin/main
fatal: refusing to merge unrelated histories


$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

   git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

   git branch --set-upstream-to=origin/<branch> main


$ git log
commit 260333cb254bdd66b52557fa197e9498c3030d1b (HEAD -> main)
Author: GitHubユーザー名 <★★>
Date:   Thu Oct 20 21:43:05 2022 +0900

   first commit


$ git push origin main
To github.com:GitHubユーザー名/P25-Second-Ranking-Service.git
! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'github.com:GitHubユーザー名/P25-Second-Ranking-Service.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

   git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

   git branch --set-upstream-to=origin/<branch> main


$ git branch
* main


$ git pull main
fatal: 'main' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


$ git pull Default
f
atal: 'Default' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


$ git pull origin main
From github.com:GitHubユーザー名/P25-Second-Ranking-Service
* branch            main       -> FETCH_HEAD
fatal: refusing to merge unrelated histories


$ git pull origin branch
fatal: couldn't find remote ref branch


$ git pull branch
fatal: 'branch' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


$ git remote -v
origin  git@github.com:GitHubユーザー名/P25-Second-Ranking-Service.git (fetch)
origin  git@github.com:GitHubユーザー名/P25-Second-Ranking-Service.git (push)


$ git config --list
http.sslcainfo=L:/9.soft/Git/mingw64/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
credential.helper=manager-core
core.longpaths=true
core.autocrlf=false
core.fscache=true
core.symlinks=false
core.fsmonitor=true
pull.rebase=false
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=main
user.name=GitHubユーザー名
user.email=★★
core.autocrlf=false
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
safe.directory=L:/1_Hp/0_sakura/2018server/var
safe.directory=L:/1_Hp/0_sakura/2018server/var/www/html/1-p41
safe.directory=L:/9.soft/Git
difftool.sourcetree.cmd='' "$LOCAL" "$REMOTE"
mergetool.sourcetree.cmd=''
mergetool.sourcetree.trustexitcode=true
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
remote.origin.url=git@github.com:GitHubユーザー名/P25-Second-Ranking-Service.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*


$ git config remote.origin.url
git@github.com:GitHubユーザー名/P25-Second-Ranking-Service.git


$ git status
On branch main
nothing to commit, working tree clean


$ git branch -a
* main
 remotes/origin/main


$ git pull branch main
fatal: 'branch' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


$ git fetch

$ git merge origin/main
fatal: refusing to merge unrelated histories


$ git push origin main
To github.com:GitHubユーザー名/P25-Second-Ranking-Service.git
! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'github.com:GitHubユーザー名/P25-Second-Ranking-Service.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


$ git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'github.com:GitHubユーザー名/P25-Second-Ranking-Service.git'


$ git log
commit 260333cb254bdd66b52557fa197e9498c3030d1b (HEAD -> main)
Author: GitHubユーザー名 <★★>
Date:   Thu Oct 20 21:43:05 2022 +0900

   first commit


$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

   git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

   git branch --set-upstream-to=origin/<branch> main


$ git branch --set-upstream-to=origin/<branch> main
bash: branch: No such file or directory


$ git branch --set-upstream-to=origin/ main
fatal: the requested upstream branch 'origin/' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
hint: Disable this message with "git config advice.setUpstreamFailure false"


$ git branch --set-upstream-to=origin/main
branch 'main' set up to track 'origin/main'.


$ git push origin main
To github.com:GitHubユーザー名/P25-Second-Ranking-Service.git
! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'github.com:GitHubユーザー名/P25-Second-Ranking-Service.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


$ git pull origin main
From github.com:GitHubユーザー名/P25-Second-Ranking-Service
* branch            main       -> FETCH_HEAD
fatal: refusing to merge unrelated histories


$ git pull origin branch
fatal: couldn't find remote ref branch



Git BASH 作業履歴 2022/10/20 / P48 site-rank(First-Ranking-Service) 2 / P25をP48のリポジトリへ反映させていたので、「git push -f origin main」で強制上書き実行

Git BASH 作業履歴 2022/10/21 / P13 pagerankingなど(Third-Ranking-Service) / 入力順番を間違えたためグダグダになってしまった例



類似度ページランキング
順位 ページタイトル抜粋
1 Git BASH 作業履歴 2022/10/20 / P25 manga-user-ranking(Second-Ranking-Service) / 「Add a README」後「git merge --allow-unrelated-histories origin/main」実行して、「README」もコミット履歴に含める 36
2 Git BASH 作業履歴 2022/10/20 / P48 site-rank(First-Ranking-Service) / 「Add a README」後「git push -f origin main」実行したため、「README」削除 33
3 Git BASH 作業履歴 2022/10/21 / P28 site-ranking(4Th-Ranking-Service) / 他の「.git」ディレクトリが存在した状態のまま下記gitコマンドを実行したため、意図せず「submodule」化されてしまった例 32
4 Git BASH 作業履歴 2022/10/20 / P48 site-rank(First-Ranking-Service) 2 / P25をP48のリポジトリへ反映させていたので、「git push -f origin main」で強制上書き実行 30
5 Git BASH 作業履歴 2022/10/21 / P13 pagerankingなど(Third-Ranking-Service) / 入力順番を間違えたためグダグダになってしまった例 28
6 Git 失敗履歴2。「$ git reset」→ ソースコード削除。※Git BASH 経由で Windows10 から GitHub へ PUSH しようとするも、誤ってソースコードを削除してしまう 23
7 「2023 年 4 月 30 日」前後にTwitterアカウントが「SUSPENDED This App has violated Twitter Rules and policies.」と表示された場合には、「Downgrade」ボタンを押した方がよいと思われます。 21
8 「Twitter Developer」審査結果に通り、appを作成。しかし、いつの間にか「User is not Authorized」が表示されていたケース 20
9 意図せずSubModule(ディレクトリに白い矢印)が作成された場合は、「$ git rm -rf --cached <対象ファイル or path>」後、「$ git add <対象ファイル or path>」 19
10 「Twitter API」は、2023 年 5 月 10 日時点では、SMS認証(電話番号登録)不要でプロジェクト作成できるよう仕様変更されています。 19
11 Git BASH 経由で、Windows10 から GitHub へ PUSH する 18
12 「Email sent! We sent you a new copy of the confirmation email.」と表示されているのに、メール受信出来ない 18
13 「Windows10」へ「gitfor windows VERSION 2.18.0」をインストール 18
14 「Windows10」へ「gitfor windows VERSION 2.22.0」をインストール 18
15 「Twitter API」を利用するためには? / Twitter API v1.1 / OAuth 1.0A / OAuth 2.0 17
16 「Twitter Developers」でアプリケーションを新規作成するためには? SMS認証用コードを確認可能な電話番号の登録が必要 17
17 意図せずSubModuleが作成された場合は、「$ git rm -rf --cached <対象ファイル or path>」後、「$ git add <対象ファイル or path>」 17
18 Knuth–Morris–Pratt algorithm border 17
19 GitHubのリポジトリ名を変更するためには、GitHubのWebページへアクセス。[Repositories] - [Settings]タブをクリック後、[Repository name]へ入力後、[Rename]ボタンをクリックする 17
20 2022 年 10 月 28 時点における、私が理想とする(Web系プロジェクトバックアップ用途)gitコマンド実行履歴。※これまで一度もこの通りに実行できたことはない 17
2024/4/20 3:22 更新
週間人気ページランキング / 4-13 → 4-19
順位 ページタイトル抜粋 アクセス数
1 動画対応 | プログラミング 7
1 Twitter アカウント管理 | Twitter Developer(Twitter) 7
2 本 | ブックマーク 6
3 GitHubリモートリポジトリ名には日本語を使用できない。使用すると、ハイフンへ自動置換されてしまう | GitHub(Git) 5
4 気になるアプリ | ブックマーク 3
4 Windows10で使用できるGitクライアント | GitHub(Git) 3
5 同じ携帯電話番号でも、複数の「Twitter Developers」アカウントを作成可能 | Twitter Developer(Twitter) 2
5 RTだけ表示するやつ / 2020/3/20時点の結論 / Link 2
6 Git BASH(Git) カテゴリー 1
6 2012年 1
6 Git BASH 作業履歴 2022/10/20 / P48 site-rank(First-Ranking-Service) / 「Add a README」後「git push -f origin main」実行したため、「README」削除 | Git BASH(Git) 1
6 SFC(プログラミング) カテゴリー 1
6 「Twitter API」は、2023 年 5 月 10 日時点では、SMS認証(電話番号登録)不要でプロジェクト作成できるよう仕様変更されています。 | Twitter API (Twitter) 1
6 3.作業ディレクトリ内へ、Gitの(空の)ローカルリポジトリを作成する / 4.作業ディレクトリ内の変更をステージングエリアへ追加してコミット候補にする / 5.インデックスに追加されたファイルをコミットする(コミットメッセージも指定する) 1
6 6.ローカルリポジトリに、リモートリポジトリを設定する / ローカルリポジトリに設定されている、リモートリポジトリ内容を一覧表示(URLも表示) / ローカルリポジトリ(mainブランチ)(の変更)を送信して、リモートリポジトリ(「origin」上の同名ブランチ)へ反映させる 1
6 和田晃一良 年表 1
6 地雷API | API(プログラミング) 1
6 Amazonアソシエイト・プログラム 1
6 開発 0 1
6 「公式サポートページでユーザ同士が回答し合う体裁」を採用しているAPI / 制限事項の詳細を中途半端にしか公開していないAPI / 問い合わせ先が、別サービスの海外掲示板になっているAPI 1
2024/4/20 1:01 更新