Increase git graph granularity

I usually add changes using git add -p , and in many cases there are large chunks with several blocks of code, separated by empty lines.

However, git will no longer be a split hunk, and I have to resort to manual editing.

How to increase the dimension of nodes so that each block of code is in a separate tray?

Edit: This is another question from Git: show more context when using git add -i or git add -e? since I'm not going to increase the context around each piece, but rather increase the number of pieces.

+5
source share
3 answers

It is impossible to do

These are the options you can do in add -p :

 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 

As soon as you use s , he will choose a piece of code that can be considered as an independent change. If you want to split it even further, you will have to use e to edit the piece, and then add it back to the scene area.

Summary:

To split the pieces, you use the s flag.
If you need to break it into even smaller pieces, you will need to manually edit it using the e option.

+4
source

As @codeWizard said in his answer , git just doesn't support what you want, and therefore it cannot be done in git add .

Now you can write the script yourself, which does the following:

  • copy your locally modified version to a location outside the tree
  • git checkout -- <changedfile> to bring the modified file into an unmodified state.
  • write your own user interface to select ranges in the file you want to add now
  • add changes to the tree.
  • git commit
  • If desired, go to 3. again
+3
source

git gui allows you to select specific lines for the stage.

Open git gui in your git repository, then right-click the line you want> Line Stage to Commit.

Now it will not allow you to edit the file (I want it to be able to open the temporary file in your favorite editor). To get around this, you can simply mark the commit message with a reminder:

 AMENDME: Add x do not forget to rename thing 

When you finish stretching the encoding, you can use git rebase -i <original branch> , mark the commit "AMENDME" with the edit command and fix it.

+2
source

Source: https://habr.com/ru/post/1239873/


All Articles