![]() ![]() Maybe commit C wasn't a disaster, but just a bit off. Because you used -hard, your files are reset to their state at commit B. ![]() You want to destroy commit C and also throw away any uncommitted changes. Say you have this, where C is your HEAD and (F) is the state of your files. I'll show you the 4 different ways you can undo a commit. But it's actually amazingly easy if you do understand. Undoing a commit is a little scary if you don't know how it works. The article What is the HEAD in git? is helpful if you want to uncommit multiple commits. Once you have this value, use the sequence of commands as explained above. You can use git reflog to determine the SHA-1 for the commit to which you wish to revert. You should understand the implications of rewriting history if you has already been published. It's almost always a bad idea to use -force prefer -force-with-lease instead, and as noted in the git manual: To remove (not revert) a commit that has been pushed to the server, rewriting history with git push origin main -force is necessary. If you do not need to edit the message, you could use the -C option.Īlternatively, to edit the previous commit (or just its commit message), commit -amend will add changes within the current index to the previous commit. git/ORIG_HEAD commit with -c ORIG_HEAD will open an editor, which initially contains the log message from the old commit and allows you to edit it. Commit the changes, reusing the old commit message.git add anything that you want to include in your new commit.Make corrections to working tree files.You'll need to add them again before you can commit them again. It will undo your last commit while leaving your working tree (the state of your files on disk) untouched. git reset is the command responsible for the undo.Undo a commit & redo $ git commit -m "Something terribly misguided" # (0: Your Accident) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |