Git In-depth Git Amend
Transcript from the "Git Amend" Lesson
>> Nina Zakharenko: So the next section is something that people tend to be very very afraid of, and that's get rebase. Show of hands. How many of you have done a rebase before? Just one?
>> Nina Zakharenko: You're too scared? You won't be scared anymore, I promise.
>> Nina Zakharenko: So rebasing. Before I'm gonna talk about rebasing, I wanna talk about amending a commit.
[00:00:32] How many of you have amended a commit with the get commit dash dash amend flag? You don't know? Just one? Two? Okay, so amend is a quick and easy shortcut that let's us make changes to the previous commit. So in this example, I made a commit and blog post about Python.
[00:00:50] But oops, I actually forgot to add the blog post. I committed index but not the post itself. So then, I'm gonna add the post and git commit amend. --get commit--amend. What that's gonna do is
>> Nina Zakharenko: It's going to add that file to the last commit. But if we look at the SHAs, we'll see that the message is the same.
[00:01:17] It's both'add a blog, post about Python, but the SHAs are different. Why is that? Does anyone remember from early on?
>> off screen: The key value thing. If the value changes, you have to have a different key.
>> Nina Zakharenko: Exactly, commits can't be edited.
>> Nina Zakharenko: Because a commit is referenced by the SHA of everything that's in it.
[00:01:38] Even if the tree's the same, everything's the same, the date is gonna be different. So we're gonna create a new commit, and that's going to look something like this. We had our original commit. Afterwards, we're adding a new commit, and that original commit becomes, it doesn't have any references pointing to it, dangling.
[00:02:01] It's eventually going to be garbage collected. So that new commit that we amended is a copy of the original. If you're just working on your local computer, do this as much as you want. It's a fast, quick, easy shortcut.