初学git 想add整个文件夹 但出现了问题 想请教各位大手

我创建了一个本地仓库 将整个文件夹移到了仓库里 但是add完以后 git status查看时出现以下情况图片描述

这是仓库的样子图片描述

git commit后也是这样图片描述

求大神告诉我这是什么情况

阅读 16.7k
3 个回答

你应该是 git add --all 以后 修改了 dapingmu 内的文件了 所以显示和你图内的一样

每次修改文件后都需要 stage 目标文件的 不然是不能commit 的

如下操作 获得返回结果和题主一样:

D:\PHP\Tmp
λ mkdir GitAdd

D:\PHP\Tmp
λ cd GitAdd\

D:\PHP\Tmp\GitAdd
λ ls

D:\PHP\Tmp\GitAdd
λ git init
Initialized empty Git repository in D:/PHP/Tmp/GitAdd/.git/

D:\PHP\Tmp\GitAdd (master)
λ mkdir dapingmu

D:\PHP\Tmp\GitAdd (master)
λ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

D:\PHP\Tmp\GitAdd (master)
λ ll
total 8
drwxr-xr-x 1 zykj 197121 0 8月   4 17:12 .
drwxr-xr-x 1 zykj 197121 0 8月   4 17:12 ..
drwxr-xr-x 1 zykj 197121 0 8月   4 17:12 .git
drwxr-xr-x 1 zykj 197121 0 8月   4 17:12 dapingmu

D:\PHP\Tmp\GitAdd (master)
λ cd dapingmu\

D:\PHP\Tmp\GitAdd\dapingmu (master)
λ touch test.txt

D:\PHP\Tmp\GitAdd\dapingmu (master)
λ cd ..

D:\PHP\Tmp\GitAdd (master)
λ git status
On branch master

Initial commit

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

        dapingmu/

nothing added to commit but untracked files present (use "git add" to track)

D:\PHP\Tmp\GitAdd (master)
λ git add --all

D:\PHP\Tmp\GitAdd (master)
λ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   dapingmu/test.txt


D:\PHP\Tmp\GitAdd (master)
λ echo 123 >> dapingmu\test.txt

D:\PHP\Tmp\GitAdd (master)
λ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   dapingmu/test.txt

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:   dapingmu/test.txt


D:\PHP\Tmp\GitAdd (master)
λ git commit -m "not add modified file"
[master (root-commit) d5e1197] not add modified file
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 dapingmu/test.txt

D:\PHP\Tmp\GitAdd (master)
λ git status
On branch master
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:   dapingmu/test.txt

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

需要这样使用

  1. git status 查看修改状态

  2. git add dapingmu 添加 或者使用 git add . 添加全部

  3. git commit dapingmu -m 'some changes' 来添加说明
    git commit 可以批量修改

  4. git push 提交修改

git帮助文档对--all选项是这样说的:

Update the index not only where the working tree has a file matching <pathspec> but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree.

If no <pathspec> is given when -A option is used, all files in the entire working tree are updated (old versions of Git used to limit the update to the current directory and its subdirectories).

大致意思是该选项会提交所有修改,包括添加、修改和删除,但是如果未指定路径的话,会提交工作树下的所有文件。

注意最后在括号中的一句话:

old versions of Git used to limit the update to the current directory and its subdirectories

即老版本的git会限制对当前目录和它的子目录的更新。

所以,我觉得可能是你的git版本比较老,建议如果只是将新添加的文件加入到暂存区的话,可以使用git add .。如果想要将删除加入到暂存区的话,使用git add -u

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
logo
Microsoft
子站问答
访问
宣传栏