Git In-depth Fixup and Autosquash
Transcript from the "Fixup and Autosquash" Lesson
>> Nina Zakharenko: Going back to amending, so as we saw earlier, using amend we can only kind of make changes to the previous commit that we made. But this is a great shortcut I use all the time that lets me amend any arbitrary commit using fixup.
>> Nina Zakharenko: I tell git that the current commit I want to make is a --fixup of a certain <SHA>.
[00:00:24] it's gonna create a new commit and mark it as a fixup. And I can git rebase -i with a --autosquash. That tells git that if it sees a commit marked with a fixup, to just squash it automatically with the right one. And when I git rebase -i, I wanna make sure that I'm specifying the parent of the <SHA> I fixed up, otherwise it won't work.
[00:00:53] And git's gonna just generate the right things for you. You can save and quit. You can use this to edit any commit in your history.
>> Nina Zakharenko: So here I wanna edit the middle commit. If I do commit --fixup, we'll see here on my git one line, that the message, that git created automatically is fixup!.
[00:01:16] That's an internal marker to git. That this commit is a fix up or an edit to this one down here that has the same commit message.
>> Nina Zakharenko: Now I could autosquash using the ref of the parent commit and that's what my rebase will look like.
>> Nina Zakharenko: So git's going to automatically reorder the commits and it'll mark the commit with a fixup action.
[00:01:46] And there we go. Once I look at my log, we'll see that the Add a blog post about Python now has a new <SHA>. It's been modified.
>> Nina Zakharenko: So a much quicker way of, you don't have to do an interactive rebase, if you just wanna modify one commit.
>> Nina Zakharenko: I'm gonna skip explaining rebase --exec. You can go back to the slide if you need to, but it's a way to specify to get to run a command after every rebase action. So as it's replaying commits, you can say git, run this test after every commit. I want to make sure that my tests pass and that I'm not checking in any breaking commits.