Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sign in on the attendance sheet!

Similar presentations


Presentation on theme: "Sign in on the attendance sheet!"— Presentation transcript:

1 Sign in on the attendance sheet!
Lecture 7 Rebasing Sign in on the attendance sheet!

2 Today Review of merging Rebasing instead of merging
Interactive rebases

3 Review: Merging To combine two branches, with a merge, we do something like git merge branch B to bring all of branch B’s changes into master via a merge commit (the commit is necessary to record the changes being brought in, especially if there are conflicts). branchA, HEAD branchB E F C D B A

4 Review: Merging To combine two branches, with a merge, we do something like git merge branch B to bring all of branch B’s changes into master via a merge commit (the commit is necessary to record the changes being brought in, especially if there are conflicts). branchA, HEAD G branchB E F This is kinda ugly to have in our git history, especially if the two branches being combined make very similar changes. Wouldn’t it be nice to combine branches in a linear fashion? C D B A

5 Review: Merging branchA, HEAD E C branchA, HEAD branchB branchB E F F This is kinda ugly to have in our git history, especially if the two branches being combined make very similar changes. Wouldn’t it be nice to combine branches in a linear fashion? D C D B B A A

6 Review: Merging branchA, HEAD E C branchA, HEAD branchB branchB E F F This is kinda ugly to have in our git history, especially if the two branches being combined make very similar changes. Wouldn’t it be nice to combine branches in a linear fashion? Enter git rebase. D C D B B A A

7 git rebase <branch-to-rebase-onto>
Example use: git rebase master Finds the common ancestor of the given branch and the current branch, then “replays” the changes of all commits of the current branch up to the ancestor onto the given branch.

8 Rebasing (assume we’re on branchA) git rebase branchB
Find the common ancestor. Replay the changes of all commits up to the ancestor on top of the given branch. Move the branch to the new top. branchA, HEAD E C branchA, HEAD branchB branchB E F F D C D B B Key idea: git rebase combines two branches while ensuring that the history looks linear. A A

9 Another rebasing problem (adapted from midterm)
What happens if I do the following? (on master) git rebase experiment master B A C D F develop experiment base

10 Another rebasing problem (adapted from midterm)
What happens if I do the following? (on base) git rebase experiment master B A C D F develop experiment base

11 Another rebasing problem (adapted from midterm)
What happens if I do the following? (on experiment) git rebase base master B A C D F develop experiment base

12 Another rebasing problem (adapted from midterm)
What happens if I do the following? (on master) git rebase develop master B A C D F develop experiment base

13 Git rebasing does not delete commits
When you rebase, you create new commits, and your branch moves to the new commits you’ve made. The old commit history still exists, it’s just inaccessible now that the branch has moved. If you really want to, you can checkout to those commits if you know the hash.

14 Git rebasing does not delete commits
branchA, HEAD C branchA, HEAD branchB branchB E F E F C D C D B B A A

15 Merge vs Rebase Both are ways of combining changes from two different branches. Generally, I prefer merges for combining branches that are distinct in their purpose (feature branches, branches for different parts of a project) and rebases for branches that are really similar (i.e. two people working on the same part of a project but create a conflict).

16 Interactive Rebase Normal rebase only allows you to “replay” changes of commits onto another branch. Interactive rebase gives you a lot more power on how this “replay” happens.

17 git rebase –i <branch-to-rebase-onto>
Example use: git rebase –i master Finds the common ancestor of the given branch and the current branch, then “replays” changes of all commits of the current branch up to the ancestor onto the given branch, but opens an editor for you to specify how the “replay” occurs.

18 Rebase Options

19 Git rebasing, but in reverse order
How do I do this? We need to apply D, then B… master, HEAD B A C D F develop experiment master, HEAD B A C D F develop experiment base base

20 Git rebasing, but deleting commits
How do I do this? We need to apply D, but not B… master, HEAD B A C D F develop experiment A C D F develop experiment master, HEAD base base

21 Git rebasing, but squashing commits
How do I do this? We need to apply B, but apply D in the same commit… master, HEAD B A C D F develop experiment master, HEAD A C D, B F develop experiment base base

22 Summary Git rebase allows you to combine branches, but maintain a linear history. Git rebase –i (interactive rebase) allows you to control precisely how commits in a linear history take place, including deleting history! Rebasing works by reapplying unshared commits onto the given branch and moving your branch there.


Download ppt "Sign in on the attendance sheet!"

Similar presentations


Ads by Google