diff --git a/ebook/en/content/028-git-rebase.md b/ebook/en/content/028-git-rebase.md index 7570c36..06d6740 100644 --- a/ebook/en/content/028-git-rebase.md +++ b/ebook/en/content/028-git-rebase.md @@ -40,3 +40,91 @@ Now you can continue working on your feature with the latest commits from dev in - #### Rebase : On the other hand `Rebase` command is used to transfer the base of the branch to be based at the last commit of the current branch which make them as one branch as shown in the picture at the top. + +### Rebasing interactively : + +You can also rebase a branche on another `interactively`. This means that you will be prompted for options. +The basic command looks like this: + +```bash +git rebase -i feature main +``` + +This will open your favorite editor (probably `vi` or `vscode`). + +Let's create an example: + +```bash +git switch main +git checkout -b feature-interactive +echo "

Rebasing interactively is super cool

" >> feature1.html +git commit -am "Commit to test Interactive Rebase" +echo "

With interactive rebasing you can do really cool stuff

" >> feature1.html +git commit -am "Commit to test Interactive Rebase" +``` + +So you are now on the `feature-interactive` branch with a commit on this branch that doesn't exist on the `main` branch, and there is a new commit on the `main` that is not in your branch. + +Now using the interactive rebase commande: + +```bash +git rebase -i main +``` + +Your favorite editor (`vi` like here or `vscode` if you've set it up correctly) should be open with something like this: + +``` +pick a21b178 Commit to test Interactive Rebase +pick cd3400c Commit to test Interactive Rebase + +# Rebase 1d152d4..a21b178 onto 1d152d4 +# +# p, pick = use commit +# r, reword = use commit, but edit the commit message +# e, edit = use commit, but stop for amending +# s, squash = use commit, but meld into previous commit +# f, fixup = like "squash", but discard this commit's log message +# x, exec = run command (the rest of the line) using shell +# b, break = stop here (continue rebase later with 'git rebase --continue') +# d, drop = remove commit +# l, label