Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Stage Specific Lines Using Git Add Patch (Edit)

stage-specific-lines-using-git-add-patch-edit.jpg

I use git add -p all the time to stage parts of a file but sometimes you need fine grain control over staging lines, edit handles that.

Quick Jump:

A while back I wrote about using git add patch which lets you pick through hunks of changes in a file to stage instead of a whole file. This works great most of the time but sometimes you can’t split a hunk to include the exact lines you want to stage.

This post will take things 1 step further and go over how to stage specific lines using the e (edit) feature of git add patch. This lets you pick and choose which lines get staged using your code editor of choice.

# Demo Video

# Timestamps

  • 0:25 – Quick demo of when splitting hunks fails
  • 1:15 – Using git add patch edit

How often do you use this method to stage commits? Let me know below.

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per year (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments