I selected these 4 for simplicity but if you want to expand and add more in the comment section, let’s do it! I know there are at least a dozen different ways of moving around in git. If you have any questions or suggestions, feel free to leave a comment below. I hope you found this article useful and learned something new. Undoing a delete operation actually means restoring the deleted commit. What are we doing here? We’re telling git to go back to the commit 1b2c3d4 and to get rid of all the changes we did (in this case, the change was deleting the commit). You can now use this commit ID to restore the changes. This means that you were at commit 1b2c3d4 and you did a reset to the previous commit. You want to look at a log like this one: 1b2c3d4 reset: moving to HEAD~1 You can see this log by running git reflog. Luckily, git keeps a log of all the commits that have been removed. In this case we entirely removed a commit and there’s no trace in the git history, so we cannot say HEAD~number anymore. If you run git reset -hard HEAD~1 and you’re not happy with the result, you can still restore the changes.Īs we’ve just seen, git reset is our time travel machine, but we need to tell it where to go. Or is it? Bonus: Restore Hard Deleted Changes ![]() The full command we need this time is git reset -hard HEAD~1 and it will delete the last commit and the changes. Warning: this will also delete any uncommitted changes you have. 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.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |