git仅添加修改的更改并忽略未跟踪的文件 [英] git add only modified changes and ignore untracked files

查看:174
本文介绍了git仅添加修改的更改并忽略未跟踪的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行了git status,下面列出了一些修改过的文件,或者在标题未更改未提交的文件下的文件。
它还列出了一些我想忽略的未跟踪文件(我在这些目录中有一个.gitignore文件)。



我想把修改过的在升级中的文件,所以我可以提交它们。当我运行git add。时,它添加了修改后的文件和我想忽略的文件进行暂存。



如何只添加修改的文件并忽略未经跟踪的文件,如果出现在下面的git状态。



另外,我的.gitignore文件是否正常工作?

  $ git status 
#在分支上添加位置
#没有为commit提交更改:
#(使用git add< file> ... 以更新将提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#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 / viewe r / searchForm.xhtml

#未经记录的文件:
#(使用git add< file> ...来包含将要提交的内容)

#.metadata /
#someProject / build /
没有更改添加到提交中(使用git add和/或git commit -a)


解决方案

理想情况下,您的 .gitignore 未被跟踪的(和被忽略的)文件被显示在状态中,使用 git add 等来添加。所以我会要求你改正你的 .gitignore $ b

您可以执行 git add -u ,以便它可以暂存修改和删除的文件。



您也可以执行 git commit -a 来仅提交修改和删除的文件。



请注意,如果您拥有2.0之前版本的Git并使用 git add。,那么您需要使用 git add -u。(请参阅 git add -A的区别 git add。)。


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")

解决方案

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 ."").

这篇关于git仅添加修改的更改并忽略未跟踪的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆