Skip to main content
  1. Blog/

How to revert your mistakes

·492 words·3 mins
Table of Contents

Intro
#

Mistakes were made
Of cause on the first day of making this blog I made a mistake and deleted a crucial directory for the Hugo web server. But I have known myself for a few years and I knew I was gonna do that sooner or later (turns out it was sooner).

So now I need to revert my changes back to a working state.

Enabling time travel
#

To make this even possible I have setup my own OneDev git services. This service keeps track of every new addition and mistake I make. OneDev also has more features that sets up this website when I release a new post, read more about my OneDev git setup in a future post.

Git is a very powerful tool and it can do many many things. But for my mistakes the easiest solution is to just revert everything I did and basically move back one commit to the past. I have (currently) simple setup with no branches and only work in main.


Process
#

Identify the problem
#

I made a commit without properly testing my blog and it broke my page. My thought process was that Hugo is building the static pages after every change completely. Next time I will read the manual before blindly deleting files (said no one ever). So after removing the folder and adding it to the .gitignore the page did not work anymore and returned 404s.

Clearly my last commit broke things, so lets travel back in time and agree that it never happened.

ABCBROKEN!Let’s go backDAll working

find the commit
#

We’re having a look at the last commits. Later we will need the hash to make git move back.

git log -n 5 --oneline  

Move into your project directory and have a look:

[bjarne ~]$cd /opt/hugo/knet
[bjarne knet]$ git log -n 5 --oneline  
0eb2276 (HEAD -> main, origin/main, origin/HEAD) removed public and added ignore  
1b096b2 manual knet: 2025-05-17 23:05:33  
0bd9849 manual knet: 2025-05-17 22:34:43  
22eb167 manual knet: 2025-05-17 22:33:23  
9287ce6 Initial

Move back in time
#

In my case 0eb2276 is the broken commit and 1b096b2 is the last good commit. Now I’m saying that I want to move one commit before the current one:

git push origin +0eb2276^:main

+ means it is a non-fastforward commit

^ means I want to move one commit behind the one I mention

in the main branch

and I want to push all of that to my server

I can use origin because on this device I created the directory by git clone

You can see your remotes by using

git remote -v

in my case:

origin https://git.kohnkenet.de/knet/ (fetch)  
origin https://git.kohnkenet.de/knet/ (push)

OneDev
#

I can see these changes in the WebUI. Navigate to your project and then to Code > Commits.

Here you can see the commits before the rollback:

screenshot showing the broken commit being the main

And here after I pushed:

screenshot showing the older commit being the main

Now I can write this article and push it to the server:

screenshot showing the new commit


Bjarne
Author
Bjarne
I’m a network engineer from Germany and like to tinker with my homelab