Just want to make a minor correction. At the time of writing (git version 2.30.2) you can edit changes in a line and stage them separately via patch mode. Though at the end of the day the changes do have to be able to be represented in terms of an entire line. Maybe that's what you meant in the first place but in case anyone needs an example:
Say I add this function to a file:
function gonnaChangeThis(thisComesLater) {
console.log("nothing here!");
console.log(thisComesLater);
}
I can do: git add -p
+ function gonnaChangeThis(thisComesLater) {
+ console.log("nothing here!");
+ console.log(thisComesLater);
+ }
+
function someOtherThing() {
(1/1) Stage this hunk [y,n,q,a,d,e,?]? e
and edit just by deleting what I don't want via the editor (in this case the func arg and corresponding line):
# Manual hunk edit mode -- see bottom for a quick guide.
@@ -37,6 +37,11 @@
+function gonnaChangeThis() {
+ console.log("nothing here!");
+}
+
save, quit, and voila:
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: exampleFile.js
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: exampleFile.js
git commit git add -p
- function gonnaChangeThis() {
+ function gonnaChangeThis(thisComesLater) {
console.log("nothing here!");
+ console.log(thisComesLater);
}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Just want to make a minor correction. At the time of writing (git version 2.30.2) you can edit changes in a line and stage them separately via patch mode. Though at the end of the day the changes do have to be able to be represented in terms of an entire line. Maybe that's what you meant in the first place but in case anyone needs an example:
Say I add this function to a file:
I can do:
git add -p
and edit just by deleting what I don't want via the editor (in this case the func arg and corresponding line):
save, quit, and voila:
git commit
git add -p