Git添加不添加文件

use*_*081 9 git git-add git-commit

当我尝试git添加我的文件时,我输入了

git add <insert file names here>
Run Code Online (Sandbox Code Playgroud)

这工作正常.但是,当我尝试做的时候

git commit -a
Run Code Online (Sandbox Code Playgroud)

我的git存储库告诉我它是空的.输出的是:

# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed) 
#
<insert name of files here>

nothing added to commit but untracked files present (use "git add" to track)
Run Code Online (Sandbox Code Playgroud)

可能有人知道解决方案吗?谢谢.

Kyl*_*son 17

而且您可能还想确保自己位于项目的根目录中.我暂时在Rails项目上遇到了这个问题,然后意识到我在/config目录中.哎呦!#noobmistake

  • 没想到要解决它!谢谢 (3认同)
  • Git可以在git工作树的任何地方工作... (2认同)
  • @meawoppl以前从来没有给我,但我很欣赏downvote! (2认同)
  • @meawoppl No.Git理论上适用于所有地方,但`git add --all`可能不会!我认为原因是它相当于`git add .`(http://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add),因此只适用于当前和子目录.如果您有关于该主题的资金充足的知识,请仅进行投票... (2认同)

opq*_*nut 6

-agit commit覆盖暂存区域("索引")的标志.看一下手册页的内容:

   -a, --all
       Tell the command to automatically stage files that have been modified
       and deleted, but new files you have not told git about are not
       affected.
Run Code Online (Sandbox Code Playgroud)

经验法则是在使用git commit时使用平原git add.该命令git commit -a适用于您希望提交存储库中的每个更改但不能打扰git add它们的时间.

PS.git add -A很有用:它会在工作树中添加所有未忽略的新文件