![]() If you want to delete the changes, you need to add the -hard flag while running git reset. ![]() This is the case where you want to undo a commit and you don’t want to keep the changes. You can now keep working and whenever you’re ready you can do a new commit. A shortcut for HEAD is so would be the same as HEAD~1.Īfter running this command, you’ll see that the last commit is gone but the files still have your changes applied.HEAD~1 means the last commit, but you can also use HEAD~2 to undo the last 2 commits.HEAD means the current commit you’re on.-soft means that the changes will be kept.The full command we need is git reset -soft HEAD~1. The most common use case is probably to undo a commit but keep in mind that you can do much more. Git reset is kind of a time travel, really powerful but also dangerous. This is the case where you want to undo a commit, but you want to keep the changes so that you can make a new commit at a later time. is not required if all you wanted to do is to change the commit message. The commit will be updated with the new message.Īctually, git add. Once you’re done, save and close the editor. This will open your default editor and you can change the commit message. Similar situation to the previous one, but you also want to change the commit message. No extra actions required, you’re done! 2. As a result, the last commit will be updated with the new files. Instead of creating an extra commit on top, you can run git commit -amend -no-edit. Let’s start with the easiest situation, you already did a commit but you forgot to add some files. If you’re just here for the commands, you can skip the video and go straight to the article. What does that mean? I’ll get into that later.Īs usual, there’s a live demo waiting for you on my YouTube channel where I show you all the content of this article plus some extra words and scenarios. They’re similar but not exactly the same, so you can apply the best one for your situation.īonus content: I’ll also show you how to restore hard deleted changes. If you want to keep your history clean and make your mistake disappear, let me show you 4 different ways to undo a commit. ![]() Sure, you can just add a new commit, but in the long run this will mess up your git history (unless you’re closing PRs with squash).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |