この文書の現在のバージョンと選択したバージョンの差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
git:コマンド [2019/09/11 07:25] ips |
git:コマンド [2020/09/21 18:42] (現在) ips |
||
---|---|---|---|
ライン 5: | ライン 5: | ||
<code> | <code> | ||
> git init | > git init | ||
+ | </code> | ||
+ | |||
+ | ===== コミットする ===== | ||
+ | |||
+ | <code> | ||
+ | git commit -m "ファーストコミット" | ||
+ | </code> | ||
+ | |||
+ | ===== コミットメッセージの修正 ===== | ||
+ | |||
+ | <code> | ||
+ | >git commit --amend | ||
</code> | </code> | ||
ライン 96: | ライン 108: | ||
</code> | </code> | ||
+ | ===== .ignoreにweb.configを設定しても除外されない ===== | ||
+ | <code> | ||
+ | git rm --cached <filename> | ||
+ | ファイル名の大文字小文字をチェックしているので注意 | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ===== コミット間の変更ファイル名一覧 ===== | ||
+ | <code> | ||
+ | $ git diff --name-only HEAD ef99999 | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ===== コミットIDと変更メッセージ一覧 ===== | ||
+ | <code> | ||
+ | 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:コミットユーザ) | ||
+ | </code> | ||
+ | |||
+ | ===== git log でローカルとリモートを比較できる ===== | ||
+ | <code> | ||
+ | $ git log develop..origin/develop --date=short --pretty=format:"%cd %s" | ||
+ | 2019-01-01 ... | ||
+ | 2019-01-01 ... | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ===== diff でファイル名だけにする ===== | ||
+ | <code> | ||
+ | git diff 比較ブランチ名 --name-only | ||
+ | </code> | ||
+ | |||
+ | ===== 特定のファイルの更新履歴 ===== | ||
+ | <code> | ||
+ | $ git log -p [ファイル名] | ||
+ | </code> | ||
+ | |||
+ | ===== 特定の時点のファイルの中身を確認 ===== | ||
+ | |||
+ | <code> | ||
+ | $ git cat-file -p [commitID]:[ファイル名] | ||
+ | </code> | ||
+ | |||
+ | ===== originの設定 ===== | ||
+ | <code> | ||
+ | # 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 | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ===== 削除したファイルを復元する ===== | ||
+ | |||
+ | <code> | ||
+ | # ファイル名を確認する。(まだコミットしていない場合) | ||
+ | > git diff HEAD --name-only | ||
+ | |||
+ | # ファイル名を確認する。(特定のコミットにあるファイルの場合はgit logでコミットIDを確認してから) | ||
+ | > git diff HEAD <コミットID> --name-only | ||
+ | |||
+ | # 復元する。git checkout <commit> -- <FILE_PATH> | ||
+ | > git checkout HEAD -- app/src/main/res/drawable/radius.xml | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ===== 現在のブランチを確認する ===== | ||
+ | <code> | ||
+ | >git branch | ||
+ | * feature/xxxxxx //←カレントに*がついている | ||
+ | master | ||
+ | </code> | ||
+ | |||
+ | ===== ステージングの内容確認 ===== | ||
+ | <code> | ||
+ | >git status | ||
+ | On branch feature/prac_css_flex | ||
+ | Changes to be committed: | ||
+ | (use "git reset HEAD <file>..." to unstage) | ||
+ | |||
+ | modified: index.html | ||
+ | modified: main.js | ||
+ | modified: main.ts | ||
+ | modified: style.css | ||
+ | new file: tsconfig.json | ||
+ | </code> | ||
+ | |||
+ | ===== ツリー表示させる ===== | ||
+ | [[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 - グラフィカルインタフェース]] | ||
+ | <code> | ||
+ | gitk | ||
+ | gitk --all | ||
+ | </code> |