Git Internals - Git Rebase

Sdílet
Vložit
  • čas přidán 10. 06. 2023
  • In this video we understand the super powerful tool - git rebase.
    This is part 4 of a series about Merge & Rebase. In Part 1 we covered Diffs and Patches. In Part 2 we covered the basics of Merge, and Part 3 elaborated on Advanced Merges. The next part will be a recap of this series.
    If you want to play around with the repository I used and try out the commands for yourself - you can get the repo here:
    github.com/Omerr/rebase_playg...
    ======================
    `git lol` alias:
    gist.github.com/Omerr/8134a61...
    git-graph (my alias is `gg`):
    github.com/mlange-42/git-graph
    ======================
    Additional resources about Rebase:
    * jwiegley.github.io/git-from-t...
    * jwiegley.github.io/git-from-t...
    * womanonrails.com/git-rebase-onto
    * git-scm.com/book/en/v2/Git-Br...
    ======================
    📕 My book "Gitting Things Done" is officially out!
    Get it on Amazon: www.amazon.com/dp/B0CQXTJ5V5
    As an eBook: www.buymeacoffee.com/omerr/e/...
    Or read it for free at:
    www.freecodecamp.org/news/git...
    ======================
    ======================
    ☕☕☕ Support this channel:
    My mission is to create free, accessible, visual and practical tutorials. If you would like to support me on this, you can buy me a coffee :)
    www.buymeacoffee.com/omerr
    Thank you!!
    ======================
    ======================
    How do I make videos?
    I often get questions about the tools I use to create Videos - so here they are :)
    (When available, I may use affiliate links and may earn a commission, with NO additional cost to you)
    To create the hand-drawn animations, I use VideoScribe: www.awin1.com/cread.php?awinm...
    I edit using Descript: www.descript.com/?lmref=Ux4_CA
    Creating video thumbnails: snappa.com/?afmc=3uh
    Microphone: Yeti Blue: amzn.to/3QydgtP
    Drawing: Wacom Intuos: amzn.to/3pyRXwh
    ======================
    Video created by Omer Rosenbaum. All rights reserved.
  • Věda a technologie

Komentáře • 22

  • @mohamedbelkacem5366
    @mohamedbelkacem5366 Před rokem +3

    Thank you so much for sharing those amazing Git video tutorials! The quality was truly exceptional, and I found them incredibly helpful in expanding my understanding of Git. Your efforts in creating such valuable content are greatly appreciated. Keep up the fantastic work, and please continue sharing your knowledge with the community.

    • @BriefVid
      @BriefVid  Před rokem

      Thank you so much for your kind words! I really appreciate it, and I'm glad you liked my videos and found them useful. Please share it with more people so they can also benefit from them 🙏🏻

  • @randomsde4390
    @randomsde4390 Před rokem +2

    Like first, then watch. 🎉

  • @magno5157
    @magno5157 Před měsícem +1

    29:39 a mistake here... the parent of commit 17+19 is commit 15' instead of 14'

    • @BriefVid
      @BriefVid  Před měsícem

      You are absolutely right - it is supposed to be Commit 15, I got the arrow pointing to the wrong commit, my bad

  • @DevLeonardo
    @DevLeonardo Před 11 měsíci +1

    Great video, I'm getting a lot of value from it and I think I'm gonna watch all your other videos as well :D
    Just one question, at 18:47 you rebase paul_branch on main to squash commits 7 and 8. Isn't the chart on the right, wrong?
    You applied there the changes to 7' and 8' but in fact on the terminal on the left you squashed 7 and 8.
    Thank you!

    • @BriefVid
      @BriefVid  Před 11 měsíci +1

      Thank you for your kind words and your question!
      I am not sure I understood your question, but let me try to rephrase the explanation:
      What I did in the terminal is to squash commit 8 "into" commit 7, thereby creating a new commit - "Commit 7+8", which introduceds both changes of "Commit 7" and "Commit 8", in other words - the state of the tree it references is the same as of the tree after "Commit 7" and then "Commit 8". This is a new commit object, so when we "recreate" Commit 9 - it points to it as its parent, which shows at the chart on the right. at 18:51 you can see on the left the current reachable history (Commit 9' pointing to Commit 7+8...) and its corresponding drawing on the right.
      When you look at the drawing on the right please follow the "arrows" from HEAD - as it also shows the unreachable original commit 9...
      Does this clear things up?

    • @DevLeonardo
      @DevLeonardo Před 11 měsíci +1

      ​@@BriefVid At 18:51 in the terminal I see two branches having as parent Commit 4.
      john who has commits (1,2,3,4)

    • @BriefVid
      @BriefVid  Před 11 měsíci +1

      @@DevLeonardo Oh wow you are completely right. I wanted to draw it to the side to provide enough space but drew the arrow of the parent of the new commit to "commit 6" instead of "commit 4". My bad and nice catch!!

    • @DevLeonardo
      @DevLeonardo Před 11 měsíci +1

      @@BriefVid Ok, it makes sense now, thank you! :D
      By the way, I'm also creating videos about programming (and some about git!) so I kind of understand how much effort is needed to come up with a 30 minutes video, again congratulations for the quality content!

    • @BriefVid
      @BriefVid  Před 11 měsíci +1

      @@DevLeonardo Thanks a lot, I hope I can keep providing it constantly 🙏🏻🙏🏻

  • @user-cn6zd4pn6d
    @user-cn6zd4pn6d Před měsícem +1

    you say i should find comits to apply at the top of the active Branch when rebasing, but for example if history derives and merged again: for example commit1 then derives in to branches commit2 and commit3 for example ,and then commit2 also derives into commit4 and commit5 and then merged into merge commit 6, and what if i want to rebase branch that had derived history(that starts from commit2) to the top of the branch starts at commit 3? Diff(x,parent(x)) if x have two parents

    • @BriefVid
      @BriefVid  Před měsícem +1

      The short answer is - mixing rebase and merge is really difficult and error-prone. I would strongly advise against it :) You can rebase on your local linear history, but once you merge - many things could go wrong.
      For this specific question, git would, by default, take the first parent of the commit.
      I hope this helps :)

  • @lisowisko
    @lisowisko Před 10 měsíci +1

    Thank you for this great video, I'm learning so much from it! I have one question - why at 29:44 Commit 17+19 is pointing to Commit 14 and not Commit 15?

    • @BriefVid
      @BriefVid  Před 10 měsíci +1

      Thank you @ania, you are perfectly correct - it is supposed to be Commit 15, I got the arrow pointing to the wrong commit, my bad 😇

  • @DhavalAhir10
    @DhavalAhir10 Před 9 měsíci +1

    QUESTION :
    Any commit is full snapshot of stagging Area or just changes what they rememberd?
    I tried myself and found commit is not a full snapshot but only changes which they know.
    create master branch file_1 created ( 1st commit) .
    Now checkout "feat" branch.
    Do a 2nd commit file_2 created.
    Do a 3rd commit file_3 created.
    Do a 4th commit file_4 created.
    Do a 5th commit file_5 created.
    Do a 6th commit file_6 created.
    Do a 7th commit file_7 created.
    Now "git switch master".
    git cherry-pick "7th commit hash"
    And boom..
    In master you see only file_1 and after file_7 created.
    Not a full snapshot. ( I mean even 7th is latest commit in feat but it doesn't have full snapshot, just their changes what they remember at that time).
    That's why file_2 to file_6 are not comes in the master.
    Because we use cherry pick and not merge.

    • @BriefVid
      @BriefVid  Před 9 měsíci

      Thank you for your question,
      I am afraid you are confusing "commit object" with "cherry-pick".
      A commit object is the entire snapshot (more accurately, a pointer to a tree object that describes the entire snapshot).
      git cherry-pick actually computes the difference between the specified commit and its parent, and then applies them to the active commit. So it computes the diff between Commit 7 and Commit 6, and applies it on top of `master`, in your example.
      I hope this is clear

    • @DhavalAhir10
      @DhavalAhir10 Před 9 měsíci

      @@BriefVid yes yes. Today I tried very hard and I found commit is a full snapshot. You are right about cherry-pick. Even when you Cherry-pick direct merge commit which have 2 parents, you have to specify using -m that which parent do you want to get diff from.
      NOTE :
      I create file_1 in master with first commit.
      file_2 - 2nd commit
      file_3 - 3rd commit
      file_4 - 4th commit
      file_5 - 5th commit
      Now 6th commit I changes some content in file_1.
      `git diff HEAD HEAD~1`
      I checked difference between latest commit and 2nd last latest.
      Even commit - 5th just only add file_5, It was showing file_1 content changed.
      That means the commit is full snapshot...
      in 5th commit ( full snapshot) the file_1 was as it is..
      in 6th commit I changes file_1 content...
      And it will show everything where I am on 5th commit at that time to 6th commit full snapshots changes..
      Wow man you are such a genius.

    • @BriefVid
      @BriefVid  Před 9 měsíci +1

      Well done@@DhavalAhir10 , I am glad you learned from it 👏🏻👏🏻

  • @qwer6323
    @qwer6323 Před 9 měsíci

    thank you! btw can you please write the equation of area the white color used on your t-shirt?)

    • @qwer6323
      @qwer6323 Před 9 měsíci

      already found, not sure though, but seems true :)
      F - full t-shirt area
      W - constant white area (letters + circle)
      w - white segment area
      C - full internals of circle area
      (W + w) / F == w / C
      (W + w) * C == w * F
      W * C == w * (F - C)
      w = W * C / (F - C)

    • @BriefVid
      @BriefVid  Před 9 měsíci

      @@qwer6323this is the original:
      xkcd.com/688/