this post was submitted on 07 Aug 2025
82 points (98.8% liked)
Programming
22057 readers
153 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
You can via git add -i foo.bar
I believe the only issue with that is that it can only go by hunks. If your changes are sufficiently far away, you can select them separately. But if you change one function that should be in patch a, and another function 5 lines down that should be in patch b, I think you're screwed
That being said, this is all from memory, so don't quote me on it
In interactive add mode you can use
s
to split a hunk, ande
to edit it. That's usually enough for me to split things up.I usually use
git add -p
to selectively stage hunks. But ingit add -i
I think running thepatch
command does the same thing to get into patch mode.If patch mode shows you a hunk, and you only want some of the lines you can press
s
to split into smaller hunks. Then you'll be prompted whether to add each smaller hunk separately.If you want to stage a change that is on the same line as a change you don't want to stage, or on an adjacent line, then you need to use
e
to edit the hunk. Git stages whatever changes are left when you're done editing. The file in the working tree on disk is unchanged.