Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I modify git-add's hunk size?

Tags:

git

add

patch

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?

like image 260
pr1001 Avatar asked Jul 13 '09 21:07

pr1001


People also ask

How do I add changes to an index in Git?

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.

How to split lines into hunks in Git add patch?

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.

How many times can you use Git add before commit?

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.

How to add Ignored files to a commit in Git?

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


1 Answers

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 
like image 73
Jim Puls Avatar answered Sep 21 '22 23:09

Jim Puls