Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git add only modified changes and ignore untracked files

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 if 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") 
like image 403
Steve Avatar asked Aug 19 '11 16:08

Steve


People also ask

How do you git add all modified files but not untracked?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area.

Does git add untracked adds?

So, if you run git add . within a sub directory, it won't add changes to files outside that sub directory. Second, git add . adds both tracked and untracked files.

How do I commit a modified file in git?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.


1 Answers

Ideally your .gitignore should prevent the untracked (and ignored) files from being shown in status, added using git add etc. So I would ask you to correct your .gitignore

You can do git add -u so that it will stage the modified and deleted files.

You can also do git commit -a to commit only the modified and deleted files.

Note that if you have Git of version before 2.0 and used git add ., then you would need to use git add -u . (See "Difference of “git add -A” and “git add .”").

like image 96
manojlds Avatar answered Oct 01 '22 16:10

manojlds