7,166
edits
(→実用編) |
(→実用編) |
||
(21 intermediate revisions by the same user not shown) | |||
Line 91: | 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"> | ||
Line 97: | Line 105: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
= 実用編 = | |||
commit コメントメッセージ間違ったので直前の commit 取り消したい | commit コメントメッセージ間違ったので直前の commit 取り消したい | ||
<syntaxhighlight lang="bash" enclose="div"> | <syntaxhighlight lang="bash" enclose="div"> | ||
Line 105: | Line 113: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
直前のコミットをやり直し。というかcommitメッセージの書き換え。 | |||
<syntaxhighlight lang="bash" enclose="div"> | <syntaxhighlight lang="bash" enclose="div"> | ||
git commit --amend | git commit --amend | ||
Line 120: | Line 128: | ||
<syntaxhighlight lang="bash" enclose="div"> | <syntaxhighlight lang="bash" enclose="div"> | ||
git log --oneline | git log --oneline | ||
git rebase -i HEAD~ | 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 -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> |