====== よく使うコマンド ====== ===== gitリポジトリを作成する ===== > git init ===== コミットする ===== git commit -m "ファーストコミット" ===== コミットメッセージの修正 ===== >git commit --amend ===== checkout ===== > git checkout [ブランチ名] > git checkout master Switched to branch 'master' Your branch is up to date with 'origin/master'. ===== 変更を破棄する ===== git checkout . ===== orignのURLを確認する ===== >git remote -v origin https://github.com/nekotype/native-background-timer.git (fetch) origin https://github.com/nekotype/native-background-timer.git (push) >git config --get remote.origin.url https://github.com/nekotype/native-background-timer.git ===== orignに手動でpushする ===== git push -u origin master ===== 特定のコミットに戻す ===== git logでコミットidを調べて git reset --hard [コミットid] ===== 現在のブランチ名を確認する ===== > git rev-parse --abbrev-ref HEAD ===== ブランチを切り替える ===== > git checkout master ===== ブランチを作る ===== //ブランチを作る git branch [new branch] //コミットからブランチを作る git branch [new branch] [commmit] //ブランチを作って切り替える git checkout -b [new branch] ===== コミットメッセージを修正する ===== git commit --amend -m "変更後のメッセージ" ===== インデックスに追加 ===== git add . //すべてのファイル・ディレクトリ git add *.css //すべてのCSSファイル git add -n //追加されるファイルを調べる git add -u //変更されたファイルを追加する git rm --cached //addしてしまったファイルを除外 ===== 追加の取消し ===== // git init 後、初回コミットまで git rm --cached -r .      // 全てのファイルを取り消し git rm --cached -r file_name // 特定のファイルを取り消し // 初回コミット以降    git reset HEAD // 全てのファイルを取り消し git reset HEAD file_name // 特定のファイルを取り消し ===== .ignoreにweb.configを設定しても除外されない ===== git rm --cached  ファイル名の大文字小文字をチェックしているので注意 ===== コミット間の変更ファイル名一覧 ===== $ git diff --name-only HEAD ef99999 ===== コミットIDと変更メッセージ一覧 ===== git log --date=short --no-merges --pretty=format:"%cd %s %h (@%cn) " --date=short : 日付をYYYY-MM-DDで表示 --no-merges : マージリクエストを除く --pretty=format : 表示フォーマットを指定できる(%cd:日付、%s:件名、%h:ハッシュ(短縮版)、%cn:コミットユーザ) ===== git log でローカルとリモートを比較できる ===== $ git log develop..origin/develop --date=short --pretty=format:"%cd %s" 2019-01-01 ... 2019-01-01 ... ===== diff でファイル名だけにする ===== git diff 比較ブランチ名 --name-only ===== 特定のファイルの更新履歴 ===== $ git log -p [ファイル名] ===== 特定の時点のファイルの中身を確認 ===== $ git cat-file -p [commitID]:[ファイル名] ===== originの設定 ===== # originの設定 >git remote add origin https://github.com/nekotype/xxxxx.git # push >git push -u origin master # fatal: remote origin already exists.とでてoriginを設定できないときは一旦削除して再登録。 >git remote rm origin ===== 削除したファイルを復元する ===== # ファイル名を確認する。(まだコミットしていない場合) > git diff HEAD --name-only # ファイル名を確認する。(特定のコミットにあるファイルの場合はgit logでコミットIDを確認してから) > git diff HEAD <コミットID> --name-only # 復元する。git checkout -- > git checkout HEAD -- app/src/main/res/drawable/radius.xml ===== 現在のブランチを確認する ===== >git branch * feature/xxxxxx //←カレントに*がついている master ===== ステージングの内容確認 ===== >git status On branch feature/prac_css_flex Changes to be committed: (use "git reset HEAD ..." to unstage) modified: index.html modified: main.js modified: main.ts modified: style.css new file: tsconfig.json ===== ツリー表示させる ===== [[https://git-scm.com/book/ja/v2/Appendix-A%3A-%E3%81%9D%E3%81%AE%E4%BB%96%E3%81%AE%E7%92%B0%E5%A2%83%E3%81%A7%E3%81%AEGit-%E3%82%B0%E3%83%A9%E3%83%95%E3%82%A3%E3%82%AB%E3%83%AB%E3%82%A4%E3%83%B3%E3%82%BF%E3%83%95%E3%82%A7%E3%83%BC%E3%82%B9|A1.1 Appendix A: その他の環境でのGit - グラフィカルインタフェース]] gitk gitk --all