LoginSignup
2
0

More than 5 years have passed since last update.

GitHubコマンドまとめ

Last updated at Posted at 2018-05-19

GitHコマンド備忘録

  • git config --global user.name="" - ユーザ名の設定
  • git config --global user.email="" - メールアドレスの設定
  • git config --list - コンフィグ一覧
  • git init - リポジトリ初期化
  • git status - リポジトリ状態確認
  • git add - git管理するファイルをステージ領域に追加
  • git commit -m "コメント" - 記録
    • git commit --amend - コメントメッセージを修正
  • git log
    • git log --oneline - コミットログを一行で表示
    • git log --pretty=short - コミットメッセージを1行目のみ表示
    • git log -p [ファイル名] - ファイルの差分を表示
    • git log --graph - ブランチを視覚的に表示
    • git log -n 数値 - 数値分のログを表示
  • git diff - ワークツリーとステージ領域のコミットの差分確認
    • git diff HEAD - ワークツリーと最新コミットの差分確認
  • git branch - ブランチ一覧
    • -aオプション: リモートリポジトリの情報も表示
  • `git checkout ブランチ名
    • git checkout -b ブランチ名 - ブランチ作成
    • git checkout - - 1つ前のブランチへ切り替え
    • git checkout [ファイル名] - ワーキングディレクトリの変更を打ち消す★
    • git checkout -b ブランチ origin/ブランチ リモートブランチをチェックアウト
  • git merge ブランチ名 - 現在のブランチに、指定したブランチをマージ
    • git merge --no-ff ブランチ名
    • git add コンフリクトファイル - コンフリクト解消後
    • git commit -m "コメント" - コミット * git reset - ブランチを戻す
    • git reset --hard ハッシュ値 - ブランチを分岐前に戻す * 歴史を押しつぶして修正 * git rebase -i DEAD^2
  • git commit - コミット
    • git commit --ament - コミットメッセージを修正
  • git rebase -i - 歴史を押し潰して改修
    • git rebase -i HEAD~2 - HEADERの2つまでの歴史を改修
      • Commands:
        • p, pick = use commit
        • r, reword = use commit, but edit the commit message
        • e, edit = use commit, but stop for amending
        • s, squash = use commit, but meld into previous commit
        • f, fixup = like "squash", but discard this commit's log message
        • x, exec = run command (the rest of the line) using shell
  • git log --graph
  • git remote add origin リモートリポジトリ登録
  • git push -u origin master リモートリポジトリのmasterに反映
    • -uオプションは、ローカルブランチのupstreamをorigin masterに関連付けるという意味
  • git clone リポジトリのブランチURL リモートリポジトリからブランチを取得
  • git pull origin ブランチ名 リモートリポジトリの最新データを取得
  • git clean - 未追跡のファイルを一掃。 -n, --dry-run のオプションで試し打ちできる

git revert と git reset の違い

git revert は打ち消し処理が履歴に残るが、git reset <file | commit id>は残らない

sshで

  • 鍵作成
ssh-keygen -t rsa -C "account@example.com"
  • SSH Key をクリップボードにコピーする

<Mac>

pbcopy < ~/.ssh/id_rsa.pub

<Win>

clip < ~/.ssh/id_rsa.pub
  • 疎通確認
ssh -T git@github.com
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0