git add -i (or –interactive) will give you an interactive interface where you can edit the index, to prepare what you want to have in the next commit.

You can add and take away changes to whole files, add untracked files and take away files from being tracked, but also select subsection of changes to place within the index, by selecting chunks of changes to be added, splitting those chunks, or maybe editing the diff.

Many graphical commit tools for Git (like e.g. git gui) include such feature; this could be easier to use than the instruction version.

It is very useful

  • if you have entangled changes in the working directory that you want to put in separate commits, and not all in one single commit.
  • if you are in the middle of an interactive rebase and want to split too large commit.
$ git add -i

staged unstaged path

1: unchanged +4/-4 index.js

2: +1/-0 nothing package.json

*** Commands ***

1: status 2: update 3: revert 4: add untracked

5: patch 6: diff 7: quit 8: help

What now>

The top half this output shows the present state of the index choppy into staged and unstaged columns.index.js has had 4 lines added and 4 lines removed. It is currently not staged, as the current status reports”unchanged.”

When this file becomes staged, the 4 bit will be transferred to the staged column and the
unstaged column will read “nothing.”

package.json has had one line added and has been staged. There are not any further changes since it’s been staged as indicated by the “nothing” line under the unstaged column.The bottom half shows what you can do. Either enter a number (1-8) or a letter (s, u, r, a, p, d, q, h).

status shows output just like the highest a part of the output above.update allows you to form further changes to the staged commits with additional syntax.revert will revert the staged commit information back to go HEAD.add untracked allows you to add filepaths previously untracked by version control.

Patch:- allows for one path to be selected out of an output almost likestatus for further analysis.diff :-displays what will be committed.

quit exits the command.

help :- presents further help on using this command.

If you like this post, don’t forget to share 🙂

This article is written by our awesome writer
Comments to: Interactive add in Git

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

New Dark Mode Is Here

Sign In to access the new Dark Mode reading option.

Join our Newsletter

Get our monthly recap with the latest news, articles and resources.

By subscribing you agree to our Privacy Policy.

Latest Articles

Explore Tutorials By Categories


Codeverb is simply an all in one interactive learning portal, we regularly add new topics and keep improving the existing ones, if you have any suggestions, questions, bugs issue or any other queries you can simply reach us via the contact page


Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

Read Smart, Save Time
    Strength indicator
    Log In | Lost Password