lecture 7 rebasing
play

Lecture 7 Rebasing Sign in on the attendance sheet! Today - PowerPoint PPT Presentation

Lecture 7 Rebasing Sign in on the attendance sheet! Today Review of merging Rebasing instead of merging Interactive rebases Review: Merging To combine two branches, with a merge, we do something like branchA, branchB HEAD


  1. 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 branchA, branchB HEAD git merge branch B E F to bring all of branch B’s changes into master via C D a merge commit (the commit is necessary to B record the changes being brought in, especially if there are A conflicts).

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

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

  6. Review: Merging branchA, HEAD E C branchA, branchB HEAD branchB This is kinda ugly to have in our E F F git history, especially if the two branches being combined D make very similar changes. C D Wouldn’t it be nice to combine B B branches in a linear fashion? Enter git rebase. 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. (assume we’re on branchA) Rebasing branchA, git rebase branchB HEAD E 1. Find the common ancestor. C branchA, branchB 2. Replay the changes of all HEAD branchB commits up to the ancestor E F F on top of the given branch. 3. Move the branch to the D C D new top. 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? master experiment • (on master) git rebase D experiment F B C develop A base

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

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

  12. Another rebasing problem (adapted from midterm) • What happens if I do the following? master experiment • (on master) git rebase develop D F B C develop A 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, E HEAD C branchA, branchB HEAD 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 master, HEAD experiment experiment D F F D B C C develop develop A A base base

  20. Git rebasing, but deleting commits • How do I do this? • We need to apply D, but not B… master, HEAD experiment experiment master, HEAD D F F D B C C develop develop A A 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 experiment master, HEAD experiment D F F D, B B C C develop develop A A 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 Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend