How can I add only some lines/a part of a hunk interactively with git add --patch
, if hunk shown after selecting split
is still too large?
@@ -2,9 +2,17 @@ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
diam nonumy eirmod tempor invidunt ut labore et dolore magna
aliquyam erat, sed diam voluptua. At vero eos et accusam et
justo duo dolores et ea rebum. Stet clita kasd gubergren, no
+Ut wisi enim ad minim veniam, quis nostrud exerci tation
+ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo
+consequat. Duis autem vel eum iriure dolor in hendrerit in
+vulputate velit esse molestie consequat, vel illum dolore eu
+feugiat nulla facilisis at vero eros et accumsan et iusto
+odio dignissim qui blandit praesent luptatum zzril delenit
+augue duis dolore te feugait nulla facilisi.
sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna
aliquyam erat, sed diam voluptua. At vero eos et accusam et
justo duo dolores et ea rebum. Stet clita kasd gubergren, no
sea takimata sanctus est Lorem ipsum dolor sit amet.
Update
As SO user avivir correctly notes "split", might be a valid option.
git add -p is short for git add --patch and it is a git option that allows you to make more specific commits. How it works is that it will go through all new changes in your code and display hunks of them at a time for you to decide what you would like to stage or not stage.
To make the untracked files visible to the git diff command, we staged them (using git add ) and then used the following command to create the patch: git diff --patch --staged; git diff [--options] --cached [<commit>] [--] [<path>...]
If you want to add only a part of a hunk, you can select edit from the menu that gets displayed:
Stage this hunk [y,n,q,a,d,/,e,?]?
This will start your editor where you can delete unwanted lines from the hunk that is about to be added to the index. The change is virtual, that is your file will not change.
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