Git:不添加暂存文件

标签 git

我对文件进行了更改。在尝试使用 git add 暂存文件后(像往常一样)我继续提交 git commit -m。然而,终端向我吐了这个:

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

我检查了 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:   ../../Round 1/R1C3/R1C3.py

在对管进行一些搜索后,我发现我可以用其他各种方式暂存文件,但不能使用没有标志的 git add。我可以使用 git add -Agit add -u 或使用交互式暂存的暂存。

我很困惑,也没有真正理解为什么我的 reg git add 没有工作,我开始使用 git add -A。故事变得奇怪。在我的机器上重新启动后(2011 Macbook Air 运行 Mavericks)我在同一个文件上再次尝试了 good ol' git add 经过一些更改......你猜怎么着?有效。所以我继续。

现在,不久之后,我又遇到了同样的问题。 git add 将不起作用(同一目录)。

有人知道我做错了什么吗?由于上述替代方案,这并不是一个真正的大问题,但我想了解为什么会这样。特别是因为这在过去一直对我有用,而现在,它坏了:(

**注意:我计算机上的其他版本控制项目似乎没有受到影响。

git add R1C3.py
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:   ../../Round 1/R1C3/R1C3.py
# no changes added to commit (use "git add" and/or "git commit -a")

git add -A
git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   ../../Round 1/R1C3/R1C3.py
#

最佳答案

当您执行 git add 时,它应该在与文件相同的目录中运行,或者传递文件的相对路径。由于该文件位于父目录中,git add 将找不到该文件。在您的情况下,您应该 cd ../../Round 1/R1C3/ 然后运行 ​​git add R1C3.py

git add -A 之所以有效,是因为它暂存存储库中的所有文件,而不管您在目录中的位置。

关于Git:不添加暂存文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21358205/

相关文章:

GitHub 错误消息 - 权限被拒绝(公钥)

git - 如何使用别名访问 Jenkins 中的远程 Git 存储库?

git - 在 Git 中,如何将分支与其上游分支分开?

git - 无法推送到 git 存储库

Git:仅 check out 没有存储库的文件?

git - 使用 cron 作业推送到 GitHub——权限被拒绝(公钥)

git - "Git stash apply"所有文件,一个除外

git - 不能 "git push"。 "Heroku Git error"4 天了

git - git Fetch 数据存储在哪里?

git - 如何 "reopen"最后一次 git 提交?