Step 4
Revert Changes
You can use the following command to reset (revert back changes) to an earlier commit:
git reset --hard <commit>
where <commit>
is a commit ID.
For example, I will reset my repository to the commit I've made after adding description of this app (before fixing the typo and linking to the sleepyti.me URL).
git reset --hard 79cbc98629aa98b11003c48b5a3a4cf79c78f292
Looking at the log (using git log --pretty=oneline
), I get the following:
79cbc98629aa98b11003c48b5a3a4cf79c78f292 (HEAD -> master) Add description of the app
f034c1ea747a6ab6726681d60a7bd5b097ff40b8 Create README file
Also, looking at the README.md
, the changes I've made (typo correction and URL addition) are gone! It is like I traveled back in time!
There are other commands, namely
git revert
andgit checkout
, that can be used to undo some kind of change in your repository. Consult this tutorial to learn more about each.
Commit Messages
Let's correct the typo and link to the sleepyti.me URL again. Let's also add that line about the technology used for building SleepTime App. Then, commit the changes:
git commit -am "Update description"
Look at the logs now:
03fefbc9cb2549b123cf16f9dc49eef3a19552d8 (HEAD -> master) Update description
79cbc98629aa98b11003c48b5a3a4cf79c78f292 Add description of the app
f034c1ea747a6ab6726681d60a7bd5b097ff40b8 Create README file
The last commit message is an example of a bad commit message! You should try to avoid using general descriptions like the one I just used and instead use more specific messages (like those I wrote earlier).
I recommend reading How to Write Good Commit Messages: A Practical Git Guide.