内容へ移動
Cat Paw Software
ユーザ用ツール
ログイン
サイト用ツール
検索
ツール
文書の表示
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
ログイン
>
最近の変更
メディアマネージャー
サイトマップ
トレース:
git:rebase
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
<markdown> # git rebase ## コミットを並び替える 以下のようなコミット履歴がある、これのコミット1とコミット2を入れ替えたい ``` $ git log -n 3 --oneline 7c42f82 (HEAD -> master) コミット3 2ce092f コミット2 9364cb8 コミット1 ``` 次のコマンドを実行 ``` $ git rebase -i HEAD~3 ``` エディタが開いて以下のような表示が出てくる、 ``` pick 9364cb8 コミット1 pick 2ce092f コミット2 pick 7c42f82 コミット3 # Rebase 4626091..7c42f82 onto 4626091 (3 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup [-C | -c] <commit> = like "squash" but keep only the previous # commit's log message, unless -C is used, in which case # keep only this commit's message; -c is same as -C but # opens the editor # x, exec <command> = run command (the rest of the line) using shell # b, break = stop here (continue rebase later with 'git rebase --continue') # d, drop <commit> = remove commit # l, label <label> = label current HEAD with a name # t, reset <label> = reset HEAD to a label # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>] # . create a merge commit using the original merge commit's # . message (or the oneline, if no original merge commit was # . specified); use -c <commit> to reword the commit message # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # ``` 以下のように修正して保存する ``` pick 2ce092f コミット2 pick 9364cb8 コミット1 pick 7c42f82 コミット3 ``` コミット順番が修正される(コミットを入れ替えるとcommit idが変わることに注目) ``` $ git log -n 3 --oneline d15d835 (HEAD -> master) コミット3 a880f23 コミット1 d14dc89 コミット2 ``` ## 複数のコミットをまとめる 以下のようなコミット履歴がある、これのコミット1とコミット2を1つのコミットにまとめてしまいたい ``` $ git log -n 3 --oneline d15d835 (HEAD -> master) コミット3 a880f23 コミット1 d14dc89 コミット2 ``` 次のコマンドを実行 ``` $ git rebase -i HEAD~3 ``` エディタが開いて次のような画面が表示されるので・・・ ``` pick d14dc89 コミット2 pick a880f23 コミット1 pick d15d835 コミット3 # Rebase 4626091..d15d835 onto 4626091 (3 commands) # 以下略・・・ ``` 次のように編集して保存する ``` pick d14dc89 コミット2 s a880f23 コミット1 pick d15d835 コミット3 # Rebase 4626091..d15d835 onto 4626091 (3 commands) # 以下略・・・ ``` コメント修正画面が出てくるので、適当にコメントを直して保存するとまとまる。 ``` # This is a combination of 2 commits. # This is the 1st commit message: コミット2 # This is the commit message #2: コミット1 # Please enter the commit message for your changes. Lines starting # 以下略・・・ ``` 例えば次のようなコメントに修正して(#で始まる行は無視されるので全部消してしまっても良い) ``` コミット1と2 ``` 2つのコミットが1つに纏まる。 ``` $ git log -n 3 --oneline 8bf0889 (HEAD -> master) コミット3 c9ba663 コミット1と2 4626091 initial commit ``` 2つ以上のコミットを一度にまとめたり、並べ替えも同時に行えるが、考えなしにrebaseするとコンフリクトので注意。コンフリクトした場合は手動で解消しなくてはならない。解消できそうにないなら`git rebase --abort`で修正をキャンセルできる。 ## ブランチの派生元を変更する ブランチ develop からブランチを作らなくてはならないのに master からブランチを作ってしまった…。派生元をdevelopに直したい git rebase --onto develop master まだコミット前ならば git reset --hard develop でも良い </markdown>
git/rebase.txt
· 最終更新: 2022/07/13 12:15 by
nullpon
ページ用ツール
文書の表示
以前のリビジョン
バックリンク
文書の先頭へ