How to EDIT, UNDO or CHANGE the last Git commit message with AMEND

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so you want to change your last get commit message well it's not that hard to do all you have to do is issue this command get commit D- amend DM and then in double quotes what the new updated git commit message should be if that's all you came to this video for give it a thumbs up subscribe say nice things about me when you talk about me but I have to tell you there's actually some caveats involved in using this git commit amend command it actually messes up your git commit history and if you're doing git collaboratively with other team members there's potential that you could corrupt their repositories and that's why I want to go through this get commit amend example with you I've actually cloned a repository from my GitHub account the the project called Sam and I was actually talking about some get Upstream branches and nothing goes Upstream like a salmon does um but I want to add a bad commit message here and then I want to undo it so I'm going to open up the git bash shell and I'm also going to add a new text file to this project I'll call it d. txt are we not men then if I come over here I can do the requisite get add to add the file to the staging index then I do the get commit DM and I put in a bad git commit message that we want to undo that's all done I'm going to click contrl l to clear that out and just do get log sort of the on line switch in there while we're at it and you can see well I've got my normal git commit history and then I've got that bad git commit message at the top there so how do I get rid of it how do I change it it's just this easy get commit D- amend DM for message this is the new get commit message we're going to put in there and this will be the good G commit message that we put in there to undo that bad get commit message we had in there before I click enter it says everything went swimmingly and if I open up a a new terminal window I could do this in the same new same terminal window but I want to compare the two if I come over here and do git log d-1 line you will see that bad git commit message is gone and the good git commit message is there so no problem right or there might be a problem and this is the issue you'll notice that the get commit message for the good get commit is 7 fb1 B7 and the get commit ID for the bad commit is is 5c 38939 we haven't just changed the git commit message we haven't simply updated the git commit message on a git commit we've actually deleted the old commit and created a brand new one with the new message and if you've shared your code with other people between the time where you had that bad commit and the point in time where you updated that commit um and you share again you're going to cause a lot of problems and you know I can even prove that that old git commit message is even still there if I go into the git ref log you can actually see that right there there's a back get commit message in the ref log it's two separate commits it's not simply amending a commit so if you're doing this all on your local timeline if you're doing this all on an independent Branch there's nothing to worry about okay go ahead amend the commit to undo that previous get commit message but you can get in some trouble if you're working on a server I'm going to recreate this uh situation again and do a push and a pull on that repository and show you the type of trouble you can get into so I'm going to just quickly clone that repository again so get clone I think the get URL is still on my clipboard so that pulls down that salmon repository for me and I'm going to do the similar set of steps but in between commit I'm actually going to push to the server so there we go we've got that new file in there I'm going to do the requisite G add dot I'm going to do the get commit DM bad commit message to undo and now get push okay everything's working well we've taken those changes we've pushed them up to the server but we've now got that bad commit meage message on the server well we saw how that git commit amend could be used to undo a get commit message so hey why don't we go and do that get log on line to see that bad commit message get commit D- amend DM to fix it so we'll say good get commit message and now we take a look at our git log we see that bad commit is gone so let's push and boom all of a sudden it says hey you can't actually push because you know that old commit is still up on the server you deleted it locally created a new one and then pushed which means your git commit history because you did that amend is different from the git commit history on the server so the server rejects it it doesn't like that git commit history so that's the danger you can get into you mess up with your git commit history now like always there's ways around it you can do a get push and call on Luke Skywalker and Obi-Wan Kenobi and do it with the force this will force your local git commit history to go up to the server if I now refresh on the server everything looks good right good commit message there on that d. txt file but the reality is things aren't good if other people have uh pushed and pulled from that repository if there's other people on your team that you're doing collaborative development with and you mess up their git commit history you're going to completely corrupt their local repositories and the only way for them to recover is to delete their local code and clone the repository and recreate their development environment which is not going to make you a very popular person on your team so there you go those are the ins and outs of changing a git commit history if you're just doing a local branch get commit D- amend DM and the new git commit message is fine but if you've pushed and you're working in a collaborative environment just be aware of the potential consequences so there you go now if you enjoyed that tutorial I want you head over to the servers side.com I don't think I introduced myself I'm Cameron McKenzie I'm the editor and chief over there um and we got lots of great tutorials on get and GitHub and devops if you're interested in my personal antics you can always follow me on Twitter at Cameron M cnz I'm also doing a lot of writing these days about a new programming language coming out called Mojo which is poised to replace Python and completely change the artificial intelligence and machine learning uh environment so if you want to get up to date on the latest changes in the world of software development that's just going to impact the entire industry sign up for my newsletter got lots of updates on what's happening in the world of devops tools as well and of course behind me you can see a couple of books there's my book on The Simpsons called Pickering is Springfield there's hibernate Made Easy and also been working with the young freelancer uh Darcy declute scrumptuous on Twitter and uh a lot of people have been scoring 100% on the scrum Master certification exam with their scrum master certification guide so if you're agile or you know anybody that is uh that's definitely a good read to pick up and of course if you're watching this on YouTube why don't you subscribe on YouTube
Info
Channel: Cameron McKenzie
Views: 1,247
Rating: undefined out of 5
Keywords: cameronmcnz, theserverside, java, jakarta, jakartaee, git, github, gitlab, dvcs, versioncontrol, tortoisegit, gitgui, atlassian, bitbucket, linux, azure, devops, devopstools, gitops, gitopstools, azuredevops
Id: FdRt4aTY05I
Channel Id: undefined
Length: 8min 44sec (524 seconds)
Published: Fri Feb 02 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.