Interactive reverts in Git

Git has the capability to revert only specific hunks of a commit using the git checkout --patch command. To revert the changes to file example.md made in commit 0xDEADBEEF, you would run git checkout --patch 0xDEADBEEF^ example.md and Git will open up the interactive diff editor so you can select which reverts you want to apply to your index.

Git credential helpers

Git credential helpers work via writing and reading from standard input and standard output which helped me debug an issue I was having with pass-git-helper. To get a credential helper to spit out the password, invoke it with the get action and pass in some basic key=value data. The interaction looks somewhat like given below, with < indicating the standard input of the credential helper and > indicating its standard output. ...

Managing a Nixpkgs fork without upstream tags

Enabling fetch.pruneTags causes my Nixpkgs Git checkout to constantly delete and fetch tags, since my fork is missing most tags that upstream has so they keep getting pruned when updating from origin and get re-created when fetching upstream. One solution suggested for this was setting remotes.<name>.tagOpt = "--no-tags" but that didn’t do the job for me. The thing that worked for me was to conditionally disable pruneTags for just the origin remote so it would not try to clear out the tags pulled from upstream. Achieved by running git config --local remotes.origin.pruneTags false.

Removing a Git submodule

To remove a Git submodule go through these annoying steps: git submodule deinit -f path/to/module rm -rf .git/modules/path/to/module git config -f .gitmodules --remove-section submodule.path/to/module git add .gitmodules git rm --cached path/to/module

Staging a file in Git without its contents

git add -N will stage a file without any of its changes, you can treat that as an “intention” to add as well as allow diffing additions without needing diff --cached.

Staging only tracked files in Git

git add -u will stage changes to all tracked files and leave untracked ones alone

Using your IDE as the Git commit message editor

Git has a GIT_EDITOR variable that can be overridden in specific contexts to change the editor used by Git for rebase/commit etc. I’ve configured Zed to use itself as my commit editor from the integrated terminal, which makes for a nicer experience in the IDE than having to use the terminal text editor.

Assorted Git things

A running log of Git concepts I’ve learned since I started journaling

 · Last modified:  · 3 min ·  Harsh Shandilya