Git¶
プロトコル¶
https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols
- Local Protocol
git clone path/to/repogit clone file:///path/to/repo
- HTTP Protocols
git clone https://example.com/gitproject.git
- SSH Protocol
git clone ssh://[user@]server/project.gitgit clone [user@]server:project.git
- Git Protocol ... 最も高速だが、認証がない
git clone git://server/project.git
参考:
config¶
https://git-scm.com/docs/git-config
aliasの設定¶
Examples:
Tips:
- 右辺を
!から記述すると外部コマンドを記述できる
参考:
include¶
別ファイルをincludeできる
参考:
includeIf¶
条件に基づいて別ファイルをincludeする。
参考:
pull¶
https://git-scm.com/docs/git-config#Documentation/git-config.txt-pullff
pull時の挙動を設定する。
[pull]
# 以下いずれかを指定
ff = only # fast-forwardなマージのみ許可。マージコミットを作らない
ff = false # fast-forwardなときもマージコミットを作る
rebase = merges # rebaseする。ローカルのマージコミットは消失
rebase = preserve # マージコミットを保持してrebaseする
- コミット履歴をきれいに保ちたいなら
rebase = mergesだが、リモートと歴史が変わってしまったときにローカルの履歴が失われるリスクがあると思う。rebase = preserveなら大丈夫かもしれない ff = onlyは無難な設定ff = falseを設定したい理由はわからない
関連項目:
参考:
How-to¶
See also gitコマンド
git diffをpatch適用する¶
2020-06-20記入。
今はこれでよいようだ。
メモ:
- 昔はgit diffにオプションをつけて、patchコマンドを使ってapplyしていたが、簡単になったものだ。
参考:
CommitterとAuthorを変更する¶
HEADのcommitを修正する場合:
git config --local user.name "YOUR NAME"
git config --local user.email [email protected]
git commit --amend --reset-author
過去の履歴についても変更したい場合:
git rebase -i <commit hash>
# 該当するコミットを `e` で選ぶ
git commit --amend --reset-author
git rebase --continue
参考:
歴史を改ざんする¶
See Git - 歴史の書き換え
特定のファイル・ディレクトリの履歴を完全に削除¶
## file
git filter-branch --tree-filter 'rm -f path/to/file' HEAD
## directory
git filter-branch --tree-filter 'rm -rf path/to/dir/' HEAD
参考:
マージコミットを cherry-pick¶
merge commit を cherry-pick
参考:
マージ済みブランチを掃除する¶
色んな人がやっていて、aliasに設定したりサブコマンドを作ったりしている。
自分でも2020-05-04に作った。
参考:
特定のファイルを Git 管理対象から除外する¶
①.gitignore や .git/info/exclude を使う
②既に Git 管理下にあるファイルをワーキングツリーで敢えて除外する
git update-index —assume-unchanged [ファイル名]
git update-index —skip-worktree [ファイル名]
## 確認
git ls-files -v
## 取り消し
git update-index —no-assume-unchanged [ファイル名]
git update-index —no-skip-worktree [ファイル名]
git ls-files -v の表示:
- assume-unchanged 設定のファイルは、状態が小文字で表示される
- skip-worktree 設定のファイルは、状態が S と表示される
参考:
リポジトリをサブディレクトリで分割¶
サブディレクトリが1つの場合¶
参考:
サブディレクトリが複数の場合¶
参考:
Topics¶
コミットメッセージの書き方¶
長さ:
- よく知られているガイドラインは50/72ルールというもので、タイトル行を50文字以内に、そのあと1行空けて、続くメッセージは1行が72字以内に収まるように書くというもの
文法:
- タイトル行は命令形で書くのがいいらしい
参考: