kieranpotts / dotfiles

A baseline, extensible UNIX user configuration.
MIT License
1 stars 0 forks source link

Easier Git aliases to commit individual lines/ranges within files #179

Open kieranpotts opened 1 year ago

kieranpotts commented 1 year ago

The most common workflow is to commit changes to entire files. But it is not uncommon, in development, for a working copy of a file to end up with two or more sets of unrelated changes. Development can get messy. Even when this happens, we want the eventual commit history to represent a sequence of discrete logical changes.

Both VSCode and LazyGit support this.


The magic is in the --patch argument to git-add. This instructs Git to display all changes to the files specified on a hunk-by-hunk basis and lets you choose one of the following options for each hunk:

git add --patch is actually a shortcut to features in git add --interactive, a powerful front-end for managing all aspects of the staging area. The git-add manual page is a treasure trove of worthwhile information that’s often passed over due to the traditional semantics of VCS “add” commands. Remember that git-add does a lot more than just add stuff - it’s your interface for modifying the staging area.