我已经上传了这样的文件
git add mydir
git add mydir/myfile
Run Code Online (Sandbox Code Playgroud)
然后把它们推到我的仓库
git remote add origin https://github.com/usename/myrepo.git
git push origin master
Run Code Online (Sandbox Code Playgroud)
当我看到git status -s
它说我的文件已被添加,但我无法在我的实际存储库中看到它们.有谁知道这里发生了什么?
您尚未将文件"添加"到存储库,仅添加到暂存索引.
你需要git commit
从让你改变staging index
的repository
.
git status
显示工作树和暂存索引的状态.git log
显示历史记录的状态- 换句话说,git log
将显示已提交到存储库的内容.
作为示例,请参阅此git status
输出:
git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# modified: Game.py
#
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我们可以看到要提交的更改涉及Game.py
.请注意,这些更改尚未添加到存储库中 - 它们只是暂存,准备提交,正如git status
所说的那样.
下一步是提交我们已经准备好的这些更改staging index
并将它们添加到存储库中.git commit
是这样做的命令.
这个答案,以及链接的Pro Git书,有一些很好的阅读,将帮助您了解提交到git
存储库的设置和步骤.
我在实际的存储库中看不到它们.
"实际"存储库是什么意思?我假设你的意思是你看不到本地提交,但是你可能会对你正在使用的存储库感到困惑.
您正在使用两个存储库,一个local
和一个remote
.该remote
仓库是,你的情况,在GitHub上.你在本地工作,然后git push
到远程工作.
因此,将代码更改到local
存储库的步骤如下:
working directory
.这通常是编写一些代码.commit
通过暂存更改来构建.这是使用完成的git add
.git commit
.这些步骤**本地*.这些步骤都不会对您的GitHub
存储库产生任何影响.
git push
到remote
存储库(在这种情况下,你的GitHub).要得到你的代码local
到remote
仓库,git push
被使用.
remote
存储库中已知的local
存储库:git remote -v
.GitHub
存储库,则需要添加它:.git remote add <NAME> <URL>
git clone
,这两个存储库(local
和remote
)没有任何共同的提交.没关系; 它只是意味着git
不会自动知道推送您的更改的位置,因此您必须指定:git push <NAME> master:master
.那会把你的local master
分支推到<NAME> master
分支机构.