

This command will create a new commit with the “Revert” word in the beginning of the message. If you wish to undo/revert the last commit you can do the following, using the commit hash that you get from the git log command: git revert Īfter analyzing the specific commit, if you then decide to stay in that commit state, you can undo the last commit. Example: git checkout -b new_branch_name HEAD is now at. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. This will make the working repository match the state of this exact commit.Īfter you do this you’ll get the following output: git checkout Note: checking out ''. To test a specific commit (e.g.: ), that you think has the last working version, you can type the following: git checkout You can also run git log -oneline to simplify the output: git log -oneline cdb76bf Added another feature d425161 Added one feature (.) To get the hash you can run git log, then you get this output: git log commit Author: Isabel Costa Date: Sun Feb 4 21:57:40 2018 +0000 commit Author: Isabel Costa Date: Sun Feb 4 21:42:26 2018 +0000 (.) To test a specific commit, you need the hash.

Then I have to see the changes and analyze the project’s behavior before and after the last commit. Sometimes, the change I do might not have the result I expected. So each important change that I do may have a significant impact on the functionalities of the project. In my thesis, I’m working on a project that I develop in one environment, and then test in another environment composed of multiple virtual machines. In this post I will show how I sometimes recover wrong changes (commits) in a coding project, using git on the command line.
