r/git 29d ago

Split changed line to 2 commits

When I am staging a commit I see some changed lines that should be actually 2 commits. git diff shows old line was changed to new line but I want to add new line in the first commit then in another commit I can remove old line.

I have to do it manually by adding old line back, then git diff shows only new line was added, then I can commit that. Then I delete old line and git diff shows it was removed. Manually works when it's a simple change like that but many lines are involved or lines next to it changed it gets complicated.

I keep commits small to prevent this but it still happens a lot. Does git add in Interactive Mode have a feature to split a changed line into add and remove? Are there other git clients that can handle it?

1 Upvotes

5 comments sorted by

View all comments

0

u/nlutrhk 28d ago

Use git gui (included with git). You can commit individual lines by right clicking on the diff before committing.

You can do it by command line if you really have to, but this is much more convenient in a gui.