7,166
edits
(→実用編) |
|||
(28 intermediate revisions by the same user not shown) | |||
Line 46: | Line 46: | ||
<syntaxhighlight lang="bash" enclose="div"> | <syntaxhighlight lang="bash" enclose="div"> | ||
git config --global user.email foo@bar | git config --global user.email foo@bar | ||
git config --global user.name "John Doe" | |||
git config --global core.editor emacs | git config --global core.editor emacs | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 77: | Line 78: | ||
<syntaxhighlight lang="bash" enclose="div"> | <syntaxhighlight lang="bash" enclose="div"> | ||
git branch -D 作業内容がよく分かるブランチ名 | git branch -D 作業内容がよく分かるブランチ名 | ||
</syntaxhighlight> | |||
githubの該当ブランチを消す | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git push origin :作業内容がよく分かるブランチ名 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 86: | Line 91: | ||
git pull upstream master | git pull upstream master | ||
</syntaxhighlight> | </syntaxhighlight> | ||
元のリポジトリの新ブランチを追っかける | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git fetch upstream | |||
git checkout 新ブランチ | |||
git push origin 新ブランチ | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" enclose="div"> | <syntaxhighlight lang="bash" enclose="div"> | ||
git checkout 作業ブランチ | git checkout 作業ブランチ | ||
git rebase master 作業ブランチ | git rebase master 作業ブランチ | ||
</syntaxhighlight> | |||
= 実用編 = | |||
commit コメントメッセージ間違ったので直前の commit 取り消したい | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git log | |||
git reset --hard HEAD^ | |||
git log | |||
</syntaxhighlight> | |||
直前のコミットをやり直し。というかcommitメッセージの書き換え。 | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git commit --amend | |||
</syntaxhighlight> | |||
git diff に新規追加ファイルを含める | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
# 新規ファイル作る | |||
git add -N 新規ファイルフルパス | |||
git diff | |||
</syntaxhighlight> | |||
squash と言われた場合 | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git log --oneline | |||
git rebase -i HEAD~X (X = number of commits to edit) | |||
# 先頭行以外 pick -> squash | |||
# セーブ | |||
# コメントを編集 | |||
# セーブ | |||
git push -f | |||
# こちらが安全なのかな git push --force-with-lease | |||
</syntaxhighlight> | |||
過去の commitメッセージの書き換え。 | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git log | |||
# 書き換えるcommitの直下のhash | |||
git rebase -i 直下のhash | |||
# 先頭を pick -> edit | |||
# セーブ | |||
git commit --amend | |||
# コメントを編集 | |||
# セーブ | |||
git rebase --continue | |||
git push -f | |||
# こちらが安全なのかな git push --force-with-lease | |||
</syntaxhighlight> | |||
PR送信してマージされた後の開発ブランチをマスターに同期 | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git checkout master | |||
git pull | |||
git checkout my-dev | |||
git rebase master | |||
git push | |||
</syntaxhighlight> | |||
PR送信したあとマージされる前で、アップストリーム・マスターの自分のPR以外の更新を取り込む。 | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git checkout master | |||
git pull upstream master | |||
git push | |||
git checkout my-dev | |||
git rebase master | |||
git push --force-with-lease | |||
</syntaxhighlight> | |||
upstream に新しいブランチが切られた際に、それをフォークに反映 | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git fetch upstream | |||
git checkout -b new_branch upstream/new_branch | |||
git push -u origin new_branch | |||
</syntaxhighlight> | |||
いわゆる backport | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git checkout 対象ブランチ | |||
git checkout -b 修正用ブランチ名 | |||
git cherry-pick -x <commit_hash> | |||
git push -u origin 修正用ブランチ名 | |||
# そして PR | |||
</syntaxhighlight> | |||
複数のcherrypick。注意点は開始点の指定が一つ前になるので直感的でなく、そのために"^"をつける癖をつけたほうがよい。 | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git log --oneline | |||
git cherry-pick -x {COMMIT-A}^..{COMMIT-Z} | |||
</syntaxhighlight> | |||
作業ミスして upstream と強制同期 | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git fetch upstream | |||
git reset --hard upstream/master | |||
</syntaxhighlight> | |||
タグ名でブランチ作成 | |||
<syntaxhighlight lang="bash" enclose="div"> | |||
git tag | |||
git checkout -b 新ブランチ名 refs/tags/タグ名 | |||
</syntaxhighlight> | </syntaxhighlight> |