Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add items to git index efficiently

Tags:

git

bash

I find it very tedious to write full paths when adding changed files to index. For example, i've changed 3 files, but want to commit only 2 of them:

# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   apps/frontend/config/modules/file1
#   modified:   apps/frontend/config/modules/file2
#   modified:   apps/frontend/config/modules/file3

So I have to type as much as:

git add app/frontend/modules/file1 app/frontend/modules/file3

I am looking for a way to add items by their index in the git status list? Something like

git add %1 %3
like image 335
Dziamid Avatar asked Jun 15 '26 14:06

Dziamid


2 Answers

Use interactive add:

git add -i

It'll ask you for each file, if you want to add it to the commit.

You can even go ahead and pick based on patches, which is always useful:

git add -p
like image 75
ismail Avatar answered Jun 17 '26 13:06

ismail


cd apps/frontend/config/modules
git add file1 file3
cd - #go back
like image 37
Jeff Ferland Avatar answered Jun 17 '26 12:06

Jeff Ferland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!