Git:添加未登台的文件 [英] Git: add not staging files
问题描述
在此先感谢您阅读-对于Stackoverflow社区来说,这可能是一个非常琐碎的问题,但会让我发疯.
Thank you in advance for reading - this might be a very trivial problem for the Stackoverflow community, but driving me crazy.
今天下午我在用git做一些常规工作时遇到了一个非常奇怪的问题.
I encountered a very bizarre problem this afternoon doing some routine work with git.
在文本编辑器中对文件进行了一些更改之后,我去了终端进行登载并提交.尝试使用git add
暂存文件后(像往常一样),我提交了git commit -m
终端将其吐给我:
After making some changes to a file in a text editor, I went to the terminal to stage and commit. After attempting to stage the file with git add
(like always) I went to commit git commit -m
the terminal spit this out at me:
no changes added to commit (use "git add" and/or "git commit -a")
我再次尝试了分期(因为作为一个好人,我决定再次尝试并期望得到不同的结果)并产生相同的结果.我检查了git status
:
I tried staging again (because as a good human being I decided to just try again and expect different results) and yielded the same results. I checked 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 -A
或git add -u
,也可以使用交互式登台进行演出.
After some searching around on the tubes I discovered that I could stage the file in various other ways, but not with git add
. I could use git add -A
or git add -u
or stage using interactive staging.
困惑不解并且不真正理解为什么我的reg git add
不能正常工作,我尝试使用git add -A
.这个故事很奇怪.在机器上重新启动后(2011 Macbook Air运行Mavericks),在进行了一些更改之后,我再次在同一文件上尝试了良好的git add
……您猜怎么着?有效.所以我继续.
Baffled and not really understanding why my reg git add
wasn't working, I forged on using git add -A
. The story gets weird. After a restart on my machine (2011 Macbook Air running Mavericks) I tried good ol' git add
again on the same file after some changes...and guess what? IT WORKED. So I continued on.
现在,不久之后,我又遇到了同样的问题. git add
将不起作用(同一目录).
Now, a short time later, I have the same problem again. git add
will not work (same directory).
有人知道我在做什么错吗?由于上述替代方案,这不是一个很大的问题,但是我想了解为什么会这样.特别是因为这在过去对我一直有效,而今天,它坏了:(
Does anyone have any idea what I am doing wrong? It isn't a really big problem, because of the aforementioned alternatives, but I would like to understand why this is happening. Especially because this has always worked for me in the past, and now today, it broke :(
**注意:我计算机上其他受版本控制的项目似乎没有受到影响.
**NOTE: My other version controlled projects on my computer don't seem to be affected.
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
.
When you do a git add
it should be run in the same directory as the file or passed a relative path to the file. Since the file is located in the parent directory, git add
will not find the file. In your case, you should cd ../../Round 1/R1C3/
and then run git add R1C3.py
.
git add -A
之所以起作用,是因为它暂存了存储库中的所有文件,而无视目录中的位置.
git add -A
, works because it stages all files in your repository, disregarding where you are in the directory.
这篇关于Git:添加未登台的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!