I have a file that I've been working on and then realized that I had a mistake in it a few lines above where I've been working. I quickly fixed the mistake and want to commit it before I commit the rest of my work. Great, this is where git add --patch comes in!
Except, I'm being presented with only one hunk incorporating both changes. Is it possible to manually tell git that I want two hunks?
It only adds the content of the specified file (s) at the time the add command is run; if you want subsequent changes included in the next commit, then you must run git add again to add the new content to the index. The git status command can be used to obtain a summary of which files have changes that are staged for the next commit.
Git add patch gives us many options: Stage this hunk [y,n,q,a,d,e,?]?, the s plit option allows us to split lines that are close in proximity to each other. There are times where s plit won’t conveniently break up lines into hunks, lets explore how we can manually edit those tricky splits.
This command can be performed multiple times before a commit. It only adds the content of the specified file(s) at the time the add command is run; if you want subsequent changes included in the next commit, then you must run git add again to add the new content to the index.
The git add command can be used to add ignored files with the -f (force) option. Please see git-commit[1] for alternative ways to add content to a commit. OPTIONS
In addition to 'y' and 'n', one of the answers you can give when it asks you about a hunk is 's', for 'split this hunk in to smaller hunks'. The full list:
y - stage this hunk n - do not stage this hunk q - quit, do not stage this hunk nor any of the remaining ones a - stage this and all the remaining hunks in the file d - do not stage this hunk nor any of the remaining hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help
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