I've been coding in a particular file for too long without committing, and I've ended up with a situation where I want to commit feature (A) that removes a line of code. But, in my file, I also have work on feature (B) that adds a new line of code in the place of the code removed by feature (A).
In order to commit feature (A), I want to commit the change that deletes the original line. I don't want to commit the change that adds the new line from feature (B).
How do I just commit the deletion of the line, and leave the addition as an unstaged change?
You can use git add --edit to edit the diff. Run git add --edit, search for the relevant line and delete the line that contains the code you added for B. It should start with +. You should see the line that you want to remove for A and it should start with - (keep it).
Editing the diff shouldn't modify your working directory, but I'd make a backup of the file just in case!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With