May 22, 2024
GitHub Desktop and git patches
The Github Desktop app is a good choice for newbies to start working with git. At the moment the GUI of Github Desktop does not provide a way to create and apply git patches. I take this as occasion to deliver a description to do this as macOS user with the help of some commands in the Terminal. The description assumes that all for the git patch will be or has been commited in a one commit. Replace everything that is bracketed with […]
to your needs.
Create patch file from a single commit
- Commit the neccessary changes for the patch in one commit with GitHub Desktop App.
- Right click on the new commit and hit
Copy SHA
to get the commit hash. - Switch to the Terminal and navigate to root directory of the git repository.
- Create the patch file with the command
git format-patch -1 [your-hash-of-commit] -o /Users/[mac-os-user-name]/Desktop
- Go to the desktop and watch out for the patch file.
How to get path of patch file?
- Navigate in the Terminal to the desktop where the patch file is saved.
- Get the path of patch file with the
realpath [name-of-patch-file].patch
command.
Apply patch file
- Get the path of patch file.
- Navigate in the Terminal to the root directory of the git repository.
- Apply patch file wtih the
git apply [realpath-of-patch-file]
the command. - Switch to GitHub Desktop App and check for open changes applied from the patch.