如何使用git提交一个文件?

如何使用git提交一个文件?,git,commit,Git,Commit,当我进入“git状态”时,我看到如下内容: C:\cygwin\home\GIT\webapps>git status # On branch webapp_633 # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # renamed: dir/another_dir/then_another_dir/dir_AGAIN/file.jsp -> dir

当我进入“git状态”时,我看到如下内容:

C:\cygwin\home\GIT\webapps>git status
# On branch webapp_633
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       renamed:    dir/another_dir/then_another_dir/dir_AGAIN/file.jsp -> dir/another_dir/then_another_dir/dir_AGAIN2/file.jsp
#       renamed:    dir/another_dir/then_another_dir/dir_AGAIN/file2.jsp -> dir/another_dir/then_another_dir/dir_AGAIN2/file2.jsp
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       dir/another_dir/then_another_dir/target
#       dir/dir/another_dir/then_another_dir/target
#       dir/dir/dir/another_dir/then_another_dir/target
#       dir/dir/dir/dir/another_dir/then_another_dir/target
#       dir/dir/another_dir/then_another_dir/dir/target
C:\cygwin\home\GIT\webapps>GIT状态
#在分支网站webapp_633上
#要提交的更改:
#(使用“git重置磁头…”取消分级)
#
#重命名:dir/other\u dir/then\u other\u dir/dir\u再次/file.jsp->dir/other\u dir/then\u other\u dir/dir\u AGAIN2/file.jsp
#重命名:dir/other\u dir/then\u other\u dir/dir\u再次/file2.jsp->dir/other\u dir/then\u other\u dir/dir\u AGAIN2/file2.jsp
#
#未跟踪的文件:
#(使用“git add…”包含在将提交的内容中)
#
#目录/另一个目录/然后是另一个目录/目标
#目录/目录/另一个目录/然后是另一个目录/目标
#dir/dir/dir/other_dir/then_other_dir/target
#dir/dir/dir/dir/other_dir/then_other_dir/target
#目录/目录/另一个目录/然后是另一个目录/目录/目标
通常我只使用“git commit-m”message“”来提交所有文件,但这里我只重命名了2个文件,我查看了/target文件夹,没有任何需要提交的文件


有什么帮助吗?

未跟踪的文件将不会提交,因此您只需执行以下操作:

git commit -m "message"
如果需要提交未跟踪的文件,首先需要使用git add first添加它们


我建议您尝试提交什么?使用
git commit-a
或任何其他“全局”git commit命令是非常糟糕的做法。只需使用
git add
添加相关文件。在这里,您想要的更改已经在索引中(
changes to committed
),所以只要发出一个
git commit
@Simon我正在尝试提交2个jsp文件,似乎目标文件夹中有iml/随机文件,我不想提交。@fge所以如果我只使用git commit,它将只提交2个jsp文件?或者它会提交所有文件吗?如果你指的是未跟踪的文件,那么如果你执行“git commit-m“blah”,它们就不会提交了@JoeChen强烈推荐它!还有一个问题,添加文件的简单方法是什么?假设我在“dir/dir/dir/dir/file.jsp”中有一个文件,有没有办法在不键入整个路径的情况下添加它?
git add
是递归的。只要没有其他文件被更改或是新的,您就可以使用
git add
路径的任何部分。imho最好的方法是使用.gitignore和.git/info/excludes,以便忽略任何“垃圾”文件(构建对象/类/可执行文件、核心转储、编辑器备份),然后您就可以安全地执行“git add”添加所有新文件。甚至是“git add-A”,意思是“将我所做的一切推送到staging,包括添加/删除/移动文件”。