📝 Code Tips & Developer Notes

Git Undo Commit

Published:

git reset --soft HEAD~1

This command undoes the last commit but keeps your changes staged.

How It Works

The git reset --soft HEAD~1 command moves the HEAD pointer back by one commit without changing the index or working directory. This means that all the changes from the undone commit remain staged and ready to be recommitted. It’s particularly useful when you realize you need to modify a commit message or add more changes to the same commit.

Compared to other reset modes, --soft is the least destructive: it only changes the commit history pointer. --mixed would also unstage changes, and --hard would remove them entirely.

Tip: You can replace HEAD~1 with a specific commit hash to undo multiple commits at once, but always make sure you haven’t already pushed them to a shared branch, to avoid conflicts.

Git delete all local branches

Published:

git branch | grep -v -E "(dev$|master$|stage$|\*)" | xargs git branch -D
git branch | grep -v -E "{PATTERN}" | xargs git branch -D

This command deletes all local branches except for the ones that match {PATTERN}.

When and Why to Use This Command

Over time, a Git repository can accumulate many local branches that are no longer needed. These may be remnants of merged features, old experiments, or abandoned work. Removing unused branches helps keep your repository clean and makes branch lists easier to navigate.

The first command example keeps only dev, master, and stage branches, deleting the rest. The second example lets you specify your own pattern of branches to keep.

Before deleting, it’s wise to preview the list of branches by running the command without xargs git branch -D. This ensures you don’t accidentally remove something important.

Note: The -D flag forces deletion even if a branch has unmerged changes. If you want a safer option, use -d instead, which will refuse to delete branches that haven’t been fully merged.

PyAutoGUI was unable to import pyscreeze

Published:

pyautogui.PyAutoGUIException: PyAutoGUI was unable to import pyscreeze.
(This is likely because you're running a version of Python that Pillow (which pyscreeze depends on) doesn't support currently.)
Please install this module to enable the function you tried to call.

Solution:

pip3 install pillow pyscreeze

Understanding the Error

This error occurs when the pyscreeze library, which PyAutoGUI uses for screenshot and image recognition functions, cannot be imported. The most common reason is that Pillow, a key dependency, is missing or incompatible with your current Python version.

If you recently updated Python, reinstalling these dependencies is often enough to fix the problem. Make sure you’re installing them in the correct environment — for example, your virtual environment if you use one.

On Linux, installation may also fail if system libraries like libjpeg or zlib are missing. Installing the development packages for these libraries before reinstalling Pillow usually solves the issue.

For a quick fix, run:

pip install --upgrade pillow pyscreeze

If that doesn’t work, try adding the --no-cache-dir flag to force a clean install, or compile Pillow from source with all required system dependencies in place.

SSH Local Port Forwarding (-L) #

Published:

Forward a local port to a host/port reachable from the SSH server. Useful for accessing DBs, web UIs, and services over a secure tunnel.

Basics

The form is -L [local_address:]local_port:remote_host:remote_port. Traffic to your local_port is forwarded through the SSH connection and exits at remote_host:remote_port from the server side.

Forward through an intermediate backend server:


ssh -L 127.0.0.1:3006:10.0.2.5:3306 user@backend_server

Forward directly to a database on the same host as the SSH server:


ssh -L 127.0.0.1:3006:127.0.0.1:3306 user@sql_server

PhpStorm UI Glitches After Removing KDE #

Published:

After uninstalling KDE, PhpStorm’s search panel lost navigation buttons, result counters, and the "go to file" icon. The culprit turned out to be missing system fonts (fonts-dejavu) that KDE had removed as dependencies.

Symptoms

  • No "Next/Previous Match" buttons active in the search panel.
  • "Go to file" icon absent.
  • Search still worked via Enter / Shift+F3, but UI controls were broken.

Cause

Removing KDE can also remove shared packages it had installed as dependencies. In this case, the package fonts-dejavu (a common fallback font set) was removed. JetBrains IDEs use system fonts for UI elements and fallback rendering; without them, some controls fail to render or function correctly.

Solution

Reinstall the missing font package:


sudo apt install fonts-dejavu
        

After reinstalling, restart PhpStorm. All search panel controls and icons should be restored immediately.

« 1 2 »