composer の設定
■プライベートリポジトリをcomposer update(install)で取得するための設定
下記を参考に、composerにgithubのアカウント情報を設定する
- 【直接Githubのアカウントとパスワードをセットする方法】
コマンド
$ composer config -g -a http-basic.github.com '(Githubのアカウント)' '(Githubのパスワード)'
- 【アクセストークンをセットする方法(開発環境以外は、こちらを推奨)】
コマンド
$ curl -u '(Githubのアカウント)' -d '{"scopes":["repo"],"note":"xxxxx project"}' https://api.github.com/authorizations
Enter host password for user '(Githubのアカウント)': (Githubのパスワード) ←入力+Enter
{
"id": 99999999,
"url": "https://api.github.com/authorizations/99999999",
"app": {
"name": "xxxxx project",
"url": "https://developer.github.com/v3/oauth_authorizations/",
"client_id": "00000000000000000000"
},
"token": "(アクセストークン)",
"hashed_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"token_last_eight": "xxxxxxx",
"note": "xxxxx project",
"note_url": null,
"created_at": "2018-05-30T06:46:57Z",
"updated_at": "2018-05-30T06:46:57Z",
"scopes": [
"repo"
],
"fingerprint": null
}
$ composer config -g github-oauth.github.com (アクセストークン)
gitの設定
■ git pushで正しくgithub.com上で正しくアカウントが設定されない
下記のようにコミッターが正しく投稿されない場合、git configが設定されていません。
1) user.nameを設定する
コマンド
# 設定されているか確認
$ git config --global --list | grep user.name
# 設定する
git config --global user.name "(Githubのアカウント)"
2) user.emailを設定する
コマンド
# 設定されているか確認
$ git config --global --list | grep user.email
# 設定する
git config --global user.email "(Githubで設定しているメールアドレス)"
■ gitコマンドでユーザ名・パスワード省略
- ~/.netrcにユーザ名/パスワードを書く方法(こちらを推奨)
~/.netrc
machine github.com
login (Githubのアカウント)
password (Githubのパスワード)
- urlにusername:password@を追加
{cloneしたリポジトリDir}/.git/configを編集し、[remote "origin"]項目のurlにusername:password@を追加する。
.git/config
[remote "origin"]
url = https://(Githubのアカウント):(Githubのパスワード)@github.com/username/repository.git
(参考)
https://qiita.com/azusanakano/items/8dc1d7e384b00239d4d9
■ githubのAPI制限の確認
コマンド
$ curl -sS -i -H "Authorization: token (アクセストークン)" https://api.github.com/(Githubのアカウント)/whatever
HTTP/1.1 403 Forbidden
Date: Wed, 27 Mar 2019 11:07:51 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 137
Server: GitHub.com
Status: 403 Forbidden
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 0 ← 残り回数
X-RateLimit-Reset: 1553686793 ← リセット日時
X-OAuth-Scopes: repo
X-Accepted-OAuth-Scopes: repo
X-GitHub-Media-Type: github.v3; format=json
Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Frame-Options: deny
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
Content-Security-Policy: default-src 'none'
X-GitHub-Request-Id: C18E:2438:5C4235:6FDD6F:5C9B5986
{
"message": "API rate limit exceeded for user ID 4422735.",
"documentation_url": "https://developer.github.com/v3/#rate-limiting"
}
$ date -d "@1553686793" +"%Y-%m-%d %H:%M:%S"
2019-03-27 11:39:53
■ 別のリポジトリをマージする
#(マージ先のリポジトリを取得)
git clone https://github.com/(マージ先のリポジトリ)/Example.git
cd Example
#(リモートのリポジトリ先を確認)
git remote -v
#(マージ元のリモートリポジトリをUpstreamnに指定)
git remote add upstream https://github.com/(マージ元のリポジトリ)/Example.git
#(upstreamのリモートリポジトリを読み込む)
git fetch upstream
#(ターゲットのブランチを選択してマージする)
###--(git 2.9より前)
git merge upstream/master
###--(git 2.9以降)
git merge --allow-unrelated-histories upstream/master
#---> Ctrl + X(終了)
#(pushする)
git push -u origin master
■ リポジトリを別のOrganazationのリポジトリにアップする
cd /var/www/work
#(既存のリポジトリを取得)
git clone https://github.com/NetCommons3/NetCommons3.git OldNetCommons3
cd OldNetCommons3
#(リモートのリポジトリ先を確認)
git remote -v
#(リモートのリポジトリ先を変更)
git remote set-url origin https://github.com/s-nakajima/NewNetCommons3.git
#(リモートのリポジトリ先を確認)
git remote -v
#(ブランチをmasterからmainに変更)
git branch main
git checkout main
#(Github EnterpriseのリポジトリにPush)
git push -u origin main
■ Githubのコミットを取り消す
#### コミットログを出力
git log
#commit 8093f28232a62d7bd8178b48a31115de58f8f1c2 (HEAD -> master)
#Author: Shohei Nakajima <nakajimashouhei@gmail.com>
#Date: Thu Jul 6 16:35:11 2023 +0900
#
# 不要ファイル削除
#
#commit fda5b31ca1cd46269c6d4000083bebe034b112cf (tag: 3.3.6)
#Author: s-nakajima
#Date: Sat Mar 4 15:16:56 2023 +0900
#
# NetCommons 3.3.6 released.
#
#commit 6957628cd248f42d5c78fc907e89777dbf693abf
#Merge: d4d8834 be4c6b7
#Author: Shohei Nakajima
#Date: Mon Aug 22 16:46:53 2022 +0900
#
# Merge pull request #1696 from NetCommons3/s-nakajima-patch-1
#
# bootstrap-datetimepickerが6.0がリリースされたため4系に固定するように修正
#
#commit be4c6b76b3283d2b4e0774dc0a8f26c9bafd5321
#Author: Shohei Nakajima
#Date: Mon Aug 22 16:46:28 2022 +0900
#
#・・・
#### 戻したいコミットまでリセット(取り消し)する。
git reset --hard 6957628cd248f42d5c78fc907e89777dbf693abf
# --> 8093f28とfda5b31が取り消される
#### 強制Push
git push -f