Revert changes

Occasionally, you might want to revert your application to an earlier version.

git reset

You can use the following command to reset (revert changes) to an earlier commit where <commit> is a commit ID:

git reset --hard <commit>

For example, I will reset my repository to the commit I've made after adding a description of this app (before linking to the sleepyti.me URL).

git reset --hard d0f33835f7910c5ed74708e2b7a2fa85211d50c0

Looking at the log (using git log --pretty=oneline), I get the following:

d0f33835f7910c5ed74708e2b7a2fa85211d50c0 (HEAD -> main) Add description for this app
3d7292fd9530ce727fcf8323a4b2cc207d1e6ad5 Add README file

Also, looking at the README.md, the changes I've made (URL addition and note about the technology used to build the app) are gone! It is like I traveled back in time!

There are other commands, namely git revertgit checkout, and git rebase, that can be used to undo change in your repository. Consult this tutorial to learn more about each.

Let's add the 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:

af5b2587976fb43c17b992c6ca5802acefc563a6 (HEAD -> main) Update description
d0f33835f7910c5ed74708e2b7a2fa85211d50c0 Add description for this app
3d7292fd9530ce727fcf8323a4b2cc207d1e6ad5 Add README file

The last commit message is an example of a poor commit message! You should 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.