![]() ![]() Yeah, that’s good for concealing mistakes, but only if we haven’t already published this mistake on the remote server. Afterwards, it looks as if the original commit never happened. The reason is that Git replaces the original, bad commit with the amended version. A short word of warning, though: only use -amend on commits that haven’t been pushed to a remote repository, yet. The magic ingredient is the -amend flag: when using it on a commit, Git will correct the very last commit - with any staged changes and the new message. git commit -amend -m "A sensible message" We can correct both of our mistakes with the following two commands: ![]() And (as if this orthographic mess wasn’t bad enough) let’s say we also forgot to add another changed file to the staging area. git commit -m "Massage full of typohs" Let’s say we had just hit Enter on the following command: Luckily, Git makes it ridiculously easy to fix the very last commit. And in many cases, we instantly realize our mistake - right after hitting the Enter key, naturally. Another? Forgetting to add a change to the staging area. Classic case in point: making a typo in a commit message. But for the benefit of everyone else, let’s take a tour of some of the “undo” tools in Git that can save us from ourselves. Not that you and I need a safety net, of course, because we never make mistakes, right? Sure, sure. Fortunately, however, we have a wonderful safety net under our feet in the form of Git when we’re working with version control. The world of software development offers an infinite amount of ways to mess up: deleting the wrong things, coding into dead ends, littering commit messages with typos, are a mere few of the plentitude. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |