実行前の状態
feature ブランチで app.py を
このgit switch -q -c feature は、
ターミナル
git init -q -b main hello
cd hello
echo "# hello" > README.md
git add README.md
git commit -q -m "README を作る"
git switch -q -c feature
echo "print('hi')" > app.py
git add app.py
git commit -q -m "app.py を足す"
git switch -q main
echo "start" >> README.md
git commit -q -a -m "README に説明を足す"
git switch -q feature最小の例と結果
付け替えたい
ターミナル
git rebase mainSuccessfully rebased and updated refs/heads/feature.Successfully rebased は、
成功の確認
履歴が 1 本に
ターミナル
git log --oneline --graph* a1b2c3d app.py を足す
* 9f8e7d6 README に説明を足す
* 3c4d5e6 README を作るターミナル
git status -s衝突で止まったとき
付け替える
ターミナル
git switch -q main
echo "色は白" > color.txt
git add color.txt
git commit -q -m "白色"
git switch -q -c blue
echo "色は青" > color.txt
git commit -q -a -m "青色"
git switch -q main
echo "色は赤" > color.txt
git commit -q -a -m "赤色"
git switch -q blue
git rebase mainAuto-merging color.txt
CONFLICT (content): Merge conflict in color.txt
error: could not apply a1b2c3d... 青色
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply a1b2c3d... # 青色ターミナル
git status -sUU color.txtUU は、
ターミナル
git rebase --abort
git status -s何も
構文と 主要オプション
| 書き方 | すること |
|---|---|
git rebase <ブランチ名> | いまの |
git rebase --continue | 衝突をgit add した |
git rebase --abort | 付け替えを |
git rebase --skip | 衝突した |
git rebase -i HEAD~3 | 直近 3 つの |
失敗時の戻し方
push 済みの
rebase は、
衝突で止まっているとき
やめるなら git rebase --abort です。git merge --abort とは
衝突をgit add して、git rebase --continue をgit commit は
付け替えを
git reflog で、rebase (start) の
ターミナル
git refloga1b2c3d HEAD@{0}: rebase (finish): returning to refs/heads/feature
a1b2c3d HEAD@{1}: rebase (pick): app.py を足す
9f8e7d6 HEAD@{2}: rebase (start): checkout main
3c4d5e6 HEAD@{3}: checkout: moving from main to feature付け替える3c4d5e6) へ、
ターミナル
git reset --hard 3c4d5e6--hard は、git status で、
よくある疑問
rebase の 途中で、 何を しているか 分から なくなりました
git status をrebase in progress とboth modified とgit add し、git rebase --continue でgit rebase --abort で
merge と rebase は、 どちらを 使いますか
履歴が
rebase の あと、 push が 弾かれました
push 済みの
