Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

I ran "git status" and listed below are some files that were modified/or under the heading "changes not staged for commit". It also listed some untracked files that I want to ignore (I have a ".gitignore" file in these directories).

I want to put the modified files in staging so I can commit them. When I ran "git add .", it added the modified files AND the files I want to ignore to staging.

How do I add only the modified files and ignore the untracked files is presented with the git status below.

Also, are my ".gitignore" files working properly?

$ git status

# On branch addLocation

# Changes not staged for commit:

#   (use "git add <file>..." to update what will be committed)

#   (use "git checkout -- <file>..." to discard changes in working directory)

#

#       modified:   someProject/path/domain/viewer/LocationDO.java

#       modified:   someProject/path/service/ld/LdService.java

#       modified:   someProject/path/service/ld/LdServiceImpl.java

#       modified:   someProject/path/web/jsf/viewer/LocationFormAction.java

#       modified:   someProject/war/WEB-INF/classes/message/viewer/viewer.properties

#       modified:   someProject/war/page/viewer/searchForm.xhtml

#

# Untracked files:

#   (use "git add <file>..." to include in what will be committed)

#

#       .metadata/

#       someProject/build/

no changes added to commit (use "git add" and/or "git commit -a")

1 Answer

0 votes
by (50.2k points)

Your .gitignore should prevent the untracked files from being shown in status, So I would ask you to correct your .gitignore

To stage and modify the deleted files using

git add -u

For modified and deleted files to commit use:

git commit -a

Reference: https://git-scm.com/docs/git-add#Documentation/git-add.txt--u

Note: If you have git version before 2.0 you need to use git add -u.

Related questions

Browse Categories

...