ユーザー名とメールアドレスの設定
git config --global user.name "{{username}}"
git config --global user.email "{{email}}"
GPGの設定(詳細はここ)
gpg --full-gen-key --expert
gpg -a --export {{keyID}}
git config --global gpg.program gpg
git config --global user.signingkey {{keyID}}
git config --global commit.gpgsign true
git config --global tag.gpgsign true
git設定の確認は
git config --list
リポジトリの初期設定的なやつ
git init
git remote add origin {{giturl}}
git branch -M master
git add .
git commit -m "Initial commit"
git push -u origin master
クローン方法
git clone {{giturl}}
プッシュ
git push origin {{branch name}}
ブランチを作成
git branch {{branch name}}
ブランチ切り替え
git checkout {{branch name}}
ブランチ作成&切り替え
git checkout -b {{branch name}}
リモートから変更を取得する方法
git pull
ファイルの登録
git add {{file name}}
コミット
git commit -m "{{commit message}}"
変更を確認する
git status
add取り消し
git reset HEAD {{file name}}
リモートとローカルのファイルの差分を確認する
git diff {{file name}}
変更履歴をみる
git log
指定したコミットの変更点を見る
git show {{コミットのハッシュ値}}
コミットの取り消し
git reset --hard HEAD^
オプション
- –hard:コミット取り消した上でワークディレクトリの内容も書き換えたい場合
- –soft:ワークディレクトリの内容はそのままでコミットだけを取り消したい場合
- HEAD^:直前のコミット
- HEAD~{n} :n個前のコミット
コミットの打ち消し
git revert {{コミットのハッシュ値}}
コミットメッセージの修正
git commit --amend {{commit message}}
pushの取り消し
git reset --hard {{戻したいコミットのハッシュ値}}
git push -f
ブランチ名変更
git branch -m {{古いブランチ名}} {{新しいブランチ名}}
ブランチ削除
git branch -D {{branch name}}
ローカルブランチをリモートに反映
git push -u origin {{branch name}}
リモートのブランチをローカルに反映
git branch {{branch name}} origin/{{branch name}}
リモートのブランチをローカルに反映&切り替え
git branch -b {{branch name}} origin/{{branch name}}
全てのブランチを確認
git branch -a
ブランチを比較
git diff {{branch name}} {{branch name}}
ブランチをマージ
git merge {{branch name}}
ブランチをリベース
git rebase {{branch name}}
マージしようとするとrefusing to merge unrelated histories
エラーが出たときつけるオプション
--allow-unrelated-histories