Change a Git Commit in the Past with Amend and Rebase Interactive

We'll change the last commit's message and also do an interactive rebase on an older commit.
Hit the subscribe button to receive more videos like this!
REFERENCE LINKS
---------------------------------------------------
► github.com/nickjj/build-a-saa...
► github.com/nickjj/dotfiles
COURSES
---------------------------------------------------
Courses I've created that focus on web dev and deployment topics.
► nickjanetakis.com/courses/
THE TOOLS I USE / GEAR
---------------------------------------------------
► nickjanetakis.com/blog/the-to...
FOLLOW ME ELSEWHERE
---------------------------------------------------
► Twitter: / nickjanetakis
► GitHub: github.com/nickjj
TIMESTAMPS
---------------------------------------------------
0:00 -- What we're going to cover in this video
0:20 -- Use cases for wanting to change a commit
1:03 -- The project we'll be amending commits in
2:04 -- Amending the last commit message
3:15 -- Amending a file in the last commit without editing the message
5:44 -- Adding or removing multiple files and amending the last commit
6:20 -- Preparing to do an interactive rebase
7:25 -- Figuring out which commit to amend using HEAD~N or the direct SHA
9:15 -- Starting an interactive rebase with git rebase --interactive [SHA]^
10:18 -- Making our changes as part of the interactive rebase
11:39 -- Adding our changes and amending the commit during the rebase
12:33 -- Pulling the trigger and finalizing the rebase
13:21 -- Aborting a rebase in case you decide not to apply it
14:44 -- Using git stash to rebase a commit without mixing in our un-staged changes
17:35 -- Recap and do you have any questions?

Пікірлер: 78

  • @ismet55555
    @ismet555553 жыл бұрын

    I’m really liking the content and the pace of the presentation. No fluff just straight to the point.

  • @redmarine88
    @redmarine884 ай бұрын

    The content and presentation is superb, I saved a lot of time during my code patch stacks. I recommend this to all my colleagues to reduce their patch stacks time .

  • @NickJanetakis

    @NickJanetakis

    4 ай бұрын

    Thanks a lot for watching and recommending the video.

  • @UzairAli001
    @UzairAli0012 жыл бұрын

    Thanks to you I've finally learned rebase.

  • @andreivaladzko1962
    @andreivaladzko19622 жыл бұрын

    Perfect and clear explanation! Thanks a lot!

  • @2to22expiry
    @2to22expiry Жыл бұрын

    Nice presentation. To the point, quick and only meaningful content. Well done Nick.

  • @NickJanetakis

    @NickJanetakis

    Жыл бұрын

    Thanks Deepak!

  • @sauloarthur
    @sauloarthur3 жыл бұрын

    Awesome way to explain such handy and useful things. Thanks, man.

  • @NickJanetakis

    @NickJanetakis

    3 жыл бұрын

    No problem!

  • @andrewredican1413
    @andrewredican1413 Жыл бұрын

    You are a legend sir.

  • @sheelbhardwaj7400
    @sheelbhardwaj74005 ай бұрын

    this is the best video for rebase on the internet lol, I hope you go viral somehow :)

  • @NickJanetakis

    @NickJanetakis

    5 ай бұрын

    Thanks a lot, me too haha.

  • @abhishekkandari7116
    @abhishekkandari71162 жыл бұрын

    Thank you Nick.. just changed an already pushed commit message

  • @bileq6004
    @bileq60042 жыл бұрын

    Really good content. Thanks for your effort!

  • @AkashSingh-kb5vf
    @AkashSingh-kb5vf2 жыл бұрын

    Thank you. It solved my issues. Great work. 💯❤

  • @gopikrishnaks9664
    @gopikrishnaks96643 жыл бұрын

    Thanks a lot for this, very helpful.

  • @vaiterius
    @vaiterius Жыл бұрын

    You are awesome! I needed to modify some past commits where my api keys were exposed and this helped a lot.

  • @NickJanetakis

    @NickJanetakis

    Жыл бұрын

    Thanks, happy to hear it helped!

  • @shujauddin6456
    @shujauddin64562 жыл бұрын

    i usually change playback speed to 1.25 but this is already 1.5. very helpful!

  • @NickJanetakis

    @NickJanetakis

    2 жыл бұрын

    No problem, thanks for watching!

  • @kingkomfort4074
    @kingkomfort40744 ай бұрын

    Great summary my man. Speed of light pacing, I like it. ;)

  • @NickJanetakis

    @NickJanetakis

    4 ай бұрын

    Thanks a lot for watching! Do you also watch videos at 2x speed?

  • @jaywye
    @jaywye3 жыл бұрын

    Very helpful, thank you!

  • @LeoDor982
    @LeoDor982 Жыл бұрын

    You are amazing dude!

  • @NickJanetakis

    @NickJanetakis

    Жыл бұрын

    Thanks!

  • @8730Raju
    @8730Raju2 жыл бұрын

    Very helpful.. thank you so much 🙏

  • @youssefsabbagh4341
    @youssefsabbagh43412 жыл бұрын

    Excellent Video !!

  • @pcmckar
    @pcmckar Жыл бұрын

    This is such an excellent feature you have explained with this video. So useful ! Saved from doing Dravidi Pranayam!

  • @NickJanetakis

    @NickJanetakis

    Жыл бұрын

    No problem, thanks for watching!

  • @archanabhosale5101
    @archanabhosale5101 Жыл бұрын

    You saved my day, thanks a lot

  • @zindev
    @zindev2 жыл бұрын

    You teaches very well

  • @NickJanetakis

    @NickJanetakis

    2 жыл бұрын

    Thanks a lot.

  • @janoskovacs9406
    @janoskovacs94062 жыл бұрын

    Thank you very much. :)

  • @MrMOONLIGHT122
    @MrMOONLIGHT122 Жыл бұрын

    Thank You a lot.

  • @trungle6583
    @trungle65832 жыл бұрын

    Thanks a lot!

  • @KavYT
    @KavYT2 жыл бұрын

    Amazing video! I had to edit a comment from an old commit for work because I left a curse word 🤦

  • @bobby9568
    @bobby95683 жыл бұрын

    cool! nice content!

  • @NickJanetakis

    @NickJanetakis

    3 жыл бұрын

    Thanks!

  • @scrapy7806
    @scrapy7806 Жыл бұрын

    i havent seen you actually showing how to change the date in git --amend as i have been doing the same thing but after making changes in git --amend and saving them by typing in command line :wq, it was not saving them dk why

  • @il5548
    @il55482 жыл бұрын

    Thanks! A really good video!!! I have a question, how can I edit the first commit? (tried the tricks you mentioned but got an "invalid upstream" in this case)

  • @NickJanetakis

    @NickJanetakis

    2 жыл бұрын

    Invalid upstream would be unrelated to editing commits. It's hard to say what happened, you might have been on the wrong branch before starting to edit / rebase your commits. Editing the first commit is at 2:04, if you mean first as in the latest commit. If you mean first as in the first commit of the project, then 6:20 covers this workflow which would be the same for anything but the latest commit.

  • @il5548

    @il5548

    2 жыл бұрын

    @@NickJanetakis I tested again with a new project file, with only the master branch, and in total two commits. While I am in the latest commit, I used the command "git rebase --interactive HEAD~2" to try changing the commit of the first commit of the project, and eventually getting that warning again🥺 Sir, any idea on how to fix that problem? 🥺

  • @NickJanetakis

    @NickJanetakis

    2 жыл бұрын

    @@il5548 Not without any extra details sorry. What happens if you use HEAD~1?

  • @il5548

    @il5548

    2 жыл бұрын

    @@NickJanetakis HEAD~1 will have no problem, but the windows popped up will not show that commit I want to change (only the latest commit shown in my case)

  • @il5548

    @il5548

    2 жыл бұрын

    @@NickJanetakis it is like the same note that you mentioned in the video at 8:51

  • @ShitsAndGiggles124
    @ShitsAndGiggles1242 жыл бұрын

    Love this video, very helpful. How would I remove a file that I added in a previous commit? For example, I changed maybe 5 files, added them with commit --amend. But now I want to remove one file from the commit altogether. How would I do that?

  • @NickJanetakis

    @NickJanetakis

    2 жыл бұрын

    It sounds like you would still do an interactive rebase like this video except instead of adding the file you'd remove the file using git, it would be the same way to remove a file with git with git rm command and other variants (maybe adding --cached to keep the file on disk, etc.).

  • @ShitsAndGiggles124

    @ShitsAndGiggles124

    2 жыл бұрын

    @@NickJanetakis thanks!

  • @bobby9568
    @bobby95683 жыл бұрын

    @2:25 hahahahaahaha

  • @infernocaptures8739
    @infernocaptures87392 жыл бұрын

    13:02 James Madison and the first U. S. congress in 1791:

  • @NickJanetakis

    @NickJanetakis

    2 жыл бұрын

    Haha nice reference.

  • @NomedeCanal-Spyyy
    @NomedeCanal-Spyyy2 жыл бұрын

  • @kipsta1993
    @kipsta1993 Жыл бұрын

    Thanks for this tutorial, it helped me a lot ! I accidently deleted some code by another contributor and noticed it first when I wanted to rebase onto master after several commits. I approached it like this: - rebase to last commit where code still exists - copy paste the deleted code to another place - stash - continue with rebase to the next commit where I've overwritten the other contributor's code - pop stash - resolve merge conflict and continue with rebase Is this a good approach or is there a more intuitive way? Just curious :) Thanks a lot !

  • @NickJanetakis

    @NickJanetakis

    Жыл бұрын

    Hi, there might be an easier way with cherry picking parts of a commit into another commit but that's not something I know about in detail, but there's stackoverflow.com/questions/1526044/partly-cherry-picking-a-commit-with-git. I think I would have solved it your way if I had the same problem, or if it were pushed to a remote I'd probably just copy / paste it from the remote assuming it's only a couple of functions.

  • @kipsta1993

    @kipsta1993

    Жыл бұрын

    @@NickJanetakis Thanks for the input. I heard about cherry pick but didn't come to my mind as an option. I always thought when you use copy and paste in git you are doing something wrong.^^

  • @NickJanetakis

    @NickJanetakis

    Жыл бұрын

    @@kipsta1993 I wouldn't worry too much about it, I've lost track of how many times I've deleted a local repo only to clone it from a remote again because I couldn't back out of some craziness I did.

  • @ajazmiah
    @ajazmiah3 жыл бұрын

    how do i get out of the editor after changing the commit message?

  • @NickJanetakis

    @NickJanetakis

    3 жыл бұрын

    If you're using Vim you would type :q to quit, but if you wanted to write the message and quit you would do :wq.

  • @smormanyak
    @smormanyak2 жыл бұрын

    Helpful video! But how to change the first commit? When "git rebase --interactive ^ " git says "fatal: invalid upstream ^"

  • @NickJanetakis

    @NickJanetakis

    2 жыл бұрын

    That's a good question, I never had to do that before. Turns out you can run: git rebase --interactive --root , to get the "root" commit (first commit).

  • @ayushdubey8745
    @ayushdubey8745 Жыл бұрын

    How to rebase unstaged changes?

  • @NickJanetakis

    @NickJanetakis

    Жыл бұрын

    There wouldn't be anything to rebase in that case since they're not commit. kzread.info/dash/bejne/kaCs1rGSoqbQZbg.html goes over how you can unstage both tracked and tracked files if that's what you're asking.

  • @dhirenpunjabi9167
    @dhirenpunjabi91672 жыл бұрын

    It seems someone has made changes to my commit and most probably it's using amend. If you could help me with finding the id of the commit before amend, or revert back to my old commit before amend, would be very helpful

  • @NickJanetakis

    @NickJanetakis

    2 жыл бұрын

    I don't know, sorry. Maybe running a git reflog could give you some info tho. It tends to have a lot of information.

  • @dhirenpunjabi9167

    @dhirenpunjabi9167

    2 жыл бұрын

    @@NickJanetakis But I won't be able to see someone else's amend if I do git reflog in my system. Will have to reflog in the suspected system to check. Could you correct me if I'm wrong ?

  • @dhirenpunjabi9167

    @dhirenpunjabi9167

    2 жыл бұрын

    A video on this i.e. finding the suspect, would be super helpful though. If it were possible.

  • @NickJanetakis

    @NickJanetakis

    2 жыл бұрын

    @@dhirenpunjabi9167 Your reflog should have your original commit sha before it was amended?

  • @yash1152
    @yash11522 жыл бұрын

    11:07

  • @iyadomry9801
    @iyadomry9801 Жыл бұрын

    You are very fast, as one who not speake native english this is hard to understand, however thank you

  • @NickJanetakis

    @NickJanetakis

    Жыл бұрын

    You can try setting the playback speed slower. Also sorry, unfortunately talking does require saying words!

  • @yash1152
    @yash11522 жыл бұрын

    9:55 "exiting without saving will bring you back" i will call this as aborting the current command for now so, my question is, how to abort the `git commit --amend` ? say @ 3:00 i deleted all content, and exit with :q! , a new sha is still generated. which means the command was not aborted, rather it proceeded to completion.

  • @NickJanetakis

    @NickJanetakis

    2 жыл бұрын

    Hi, good question. It looks like if you try to save an empty git commit message and save it with :w then git will fail to write and abort it.

  • @yash1152

    @yash1152

    2 жыл бұрын

    @@NickJanetakis thanks for reply. yeah, i tried and it worked.

  • @lionopeter7
    @lionopeter7 Жыл бұрын

    Too fast for me

  • @turmadaembrosia6864
    @turmadaembrosia6864 Жыл бұрын

    18 minutes 💀💀

  • @NickJanetakis

    @NickJanetakis

    Жыл бұрын

    9 minutes if you 2x speed it, or potentially 30 seconds if you jump around the chapters to the specific parts you're interested in.