git-training

  1. 準備編

    • git clone git@github.com:Iovesophy/git-training.git
    • git config --local user.name "<name>"
    • git config --local user.email "<email>"
  2. 現在参照しているブランチ名を変更

    • git branch -m <new_branch_name>
  3. 新規ブランチを任意のブランチをベースにして作成

    • git checkout -b <new_branch_name> <base_branch_name>
  4. ブランチを強制的に変更(checkout)

    • git checkout -f <target_branch_name>
  5. インデックスに記録されているファイルをインデックスから解除

    • git restore --staged <filename>
  6. インデックスに記録されているファイルとリモートトラッキングブランチとの差分

    • git diff --cached origin/<branch_name>
  7. プルリクエストで発生したコンフリクトを修正

    • mergeで解決
      • git merge <to_merge_branch_name>
      • git add <filename>
      • git merge --continue
    • rebaseで解決
      • git pull --rebase origin <to_merge_branch_name>
      • git add <filename>
      • git rebase --continue
    • pullで解決
      • git pull origin <to_merge_branch_name>
      • git add <filename>
      • git merge --continue
  8. インデックスに記録されている変更を直前のコミットに混ぜる

    • git commit --amend
  9. 前にいたブランチに戻る

    • git checkout -
  10. ファイルの行単位で最終変更がどのコミットで行われたのか確認

    • git blame <filename>
  11. 直前のコミットで変更したファイルの内容を見る

    • git show
  12. コミット対象外のファイルを削除

    • git clean -f
    • option
      • d: ディレクトリも含める
      • f: 削除
      • n: Dry-run
  13. ワーキングツリーの変更を元に戻す

    • git checkout .
  14. ワーキングツリーとインデックスの変更を元に戻す

    • git checkout -f
  15. リベースをキャンセル

    • git rebase --abort
  16. cherry-pickをキャンセル

    • git cherry-pick --abort
  17. マージをキャンセル

    • git merge --abort
  18. 特定のファイルをインデックスに追加

    • git add <filename>
  19. HEADの状態をインデックスに戻す

    • git reset --mixed HEAD^
  20. ワーキングツリーとインデックスの状態をHEADに戻す

    • git reset --hard HEAD
  21. 特定のファイルのブロックだけインデックスに追加

    • git add -p <filename>
  22. ワーキングツリーとインデックスの差分をインデックスに追加

    • git add -u
  23. インデックスとHEADの差分を表示

    • git diff --cached
  24. 強制的にプッシュ

    • git push -f <repository_name> <branch_name>
  25. リモートブランチの更新を取り込んで特定のブランチをベースにリベース

    • git pull --rebase <repository_name> <branch_name>
  26. HEADのコミットメッセージを変更

    • git commit --amend -m "<message>"
    • git rebase -i HEAD~<number>
      • r, reword <commit> = use commit, but edit the commit message
  27. Gitの操作履歴を閲覧

    • git reflog
  28. 前のブランチに強制的にチェックアウト

    • git checkout - -f
  29. ワーキングツリーとインデックスの変更を直前のコミットに混ぜる

    • git commit -a --amend