How to undo a pushed commit

Oops… I just accidentally pushed a git commit containing code with a secret in plain text to a remote repo! Though it’s a private repository, I want to clean this mess up for security best practice. So, let’s fix it! Here are the last two commits. The secret resides in one of the files from the “add argocd infra to git” commit. $ git log -2 commit fe7b0510edc4fb160a16421352ba598e3f62703e (HEAD -> main, origin/main, origin/HEAD) Author: kenno <kenno@example.com> Date: Sat Dec 20 00:59:36 2025 +1100 add argocd infra to git commit c5a75ae14cf3528db1fea7677e2bdb54167037cd Author: kenno <kenno@example.com> Date: Thu Dec 18 14:38:17 2025 +1100 add basic auth middleware to longhorn httproute Since the commit had already been pushed to a remote repository, simply “undoing” the commit locally is not enough; it is required to overwrite the remote history. ...

December 20, 2025 · 2 min · 282 words · kenno

How to revert a single file to its state in main in branch

I want to reset a file stored in a git repo to its state as the main branch, and I kept forgetting how to do this. So here is how, just to remind my future self. ➜ git status On branch main Your branch is up to date with 'origin/main'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: kube-prometheus-stack-values.yaml no changes added to commit (use "git add" and/or "git commit -a") The above output shows that there is a modified file, kube-prometheus-stack-values.yaml that is not yet staged for commit. ...

February 28, 2025 · 1 min · 157 words · kenno

Changing Hugo Theme

Had you visited this blog recently, you may have noticed that the blog’s theme has changed. Here is a quick note on how I changed the theme of this blog from cayman-hugo-theme to PaperMod. For a little background, Hugo themes are installed as git submodule. Want a quick recap on how to use Git Submodule? Here is a good content [0]. First, the current theme needs to be removed: $ git submodule 4a924cef54081b61530a30bd69d442ae99916561 themes/cayman-hugo-theme (heads/master) $ git submodule deinit "themes/cayman-hugo-theme" $ git rm "themes/cayman-hugo-theme" $ git commit -m 'remove theme cayman-hugo-theme' Add a new theme, PaperMod [2] as the submodule. $ git submodule add --depth=1 https://github.com/adityatelange/hugo-PaperMod.git themes/PaperMod $ git add .gitmodules $ git add config.yml $ git commit -m 'change theme to PaperMod' $ git push Note: As each Hugo theme contains specific parameters, I also had to update the config.yml required by this new theme. A copy of a sample config.yml is available at the theme’s exampleSite [1]. ...

June 20, 2023 · 1 min · 173 words · kenno

How to add additional remote git repository

Though it’s not very common in my daily work, I occasionally need to add additional remote Git repositories mainly for pushing. In fact, I did this about 4 to 5 times already, and thought that it’d be the last time. Today, I need do this again, and I forgot! Currently, I have the following remote repository set for ‘origin’: ❯ git remote -v origin git@git.homeserver.local:kenno/ansible.git (fetch) origin git@git.homeserver.local:kenno/ansible.git (push) I wanted to add https://kenno@gitea.homeserver.local/kenno/ansible.git as the additional repo for pushing. ...

September 3, 2022 · 1 min · 193 words · kenno

Installing Xcode Command Line Tools

I need to use git on command line on macOS 11 (Big Sur), and git comes with command line developer tools. Here is how it can be done on macOS: ❯ xcode-select --install xcode-select: note: install requested for command line developer tools On a side note, I notice that every time there is an update to Big Sur, I also have to re-install this Xcode Command Line Tools. Ref: kamermanpr/install-xcodeCLT-homebrew-git.md

February 25, 2021 · 1 min · 70 words · kenno