Git 将文件添加到 repo
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7047752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git adding files to repo
提问by Stewie Griffin
I followed basic Git tutorial and added README file, which worked. Then I copied my project files to the same folder and tried to add them to repository by running
我遵循了基本的 Git 教程并添加了 README 文件,该文件有效。然后我将我的项目文件复制到同一个文件夹并尝试通过运行将它们添加到存储库
git add --all
git ci 'test' (my alias for commit)
git push origin master
and nothing got pushed.
并没有被推动。
What are the commands I should run to push my files to the remote repository (master)?
我应该运行哪些命令将我的文件推送到远程存储库(主)?
I tried to commit changes and run status but it says 'nothing to commit'. It does not recognize, that I copied lots of new files to that folder..
我试图提交更改并运行状态,但它说“没有提交”。它无法识别,我将许多新文件复制到该文件夹中。
OK, so I type: git add . (get no response from console) then type to commit, and says no changes..
好的,所以我输入: git add 。(控制台没有响应)然后输入提交,并说没有变化..
采纳答案by Stewie Griffin
I had an issue with connected repository. What's how I fixed:
我遇到了连接存储库的问题。我是如何修复的:
I deleted manually .git folder under my project folder, run git init and then it all worked.
我手动删除了项目文件夹下的 .git 文件夹,运行 git init 然后一切正常。
回答by ninjascript
This is actually a multi-step process. First you'll need to add all your files to the current stage:
这实际上是一个多步骤的过程。首先,您需要将所有文件添加到当前阶段:
git add .
You can verify that your files will be added when you commit by checking the status of the current stage:
您可以通过检查当前阶段的状态来验证提交时是否会添加您的文件:
git status
The console should display a message that lists all of the files that are currently staged, like this:
控制台应显示一条消息,列出当前暂存的所有文件,如下所示:
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: README
# new file: src/somefile.js
#
If it all looks good then you're ready to commit. Note that the commit action onlycommits to your local repository.
如果一切看起来都不错,那么您就可以提交了。请注意,提交操作仅提交到您的本地存储库。
git commit -m "some message goes here"
If you haven't connected your local repository to a remote one yet, you'll have to do that now. Assuming your remote repository is hosted on GitHub and named "Some-Awesome-Project", your command is going to look something like this:
如果您尚未将本地存储库连接到远程存储库,则现在必须这样做。假设您的远程存储库托管在 GitHub 上并命名为“Some-Awesome-Project”,您的命令将如下所示:
git remote add origin [email protected]:username/Some-Awesome-Project
It's a bit confusing, but by convention we refer to the remote repository as 'origin' and the initial local repository as 'master'. When you're ready to push your commits to the remote repository (origin), you'll need to use the 'push' command:
这有点令人困惑,但按照惯例,我们将远程存储库称为“origin”,将初始本地存储库称为“master”。当您准备好将提交推送到远程存储库(源)时,您需要使用“push”命令:
git push origin master
For more information check out the tutorial on GitHub: http://learn.github.com/p/intro.html
有关更多信息,请查看 GitHub 上的教程:http: //learn.github.com/p/intro.html
回答by James Chen
git add
puts pending files to the so called git 'index' which is local.
git add
将挂起的文件放入所谓的本地 git 'index'。
After that you use git commit
to commit (apply) things in the index.
之后,您用于git commit
提交(应用)索引中的内容。
Then use git push [remotename] [localbranch][:remotebranch]
to actually push them to a remote repository.
然后使用git push [remotename] [localbranch][:remotebranch]
将它们实际推送到远程存储库。
回答by jman
After adding files to the stage, you need to commit them with git commit -m "comment"
after git add .
. Finally, to push them to a remote repository, you need to git push <remote_repo> <local_branch>
.
将文件添加到舞台后,您需要使用git commit -m "comment"
after提交它们git add .
。最后,要将它们推送到远程存储库,您需要git push <remote_repo> <local_branch>
.
回答by Elizabeth Permi
my problem (git on macOS) was solved by using
sudo git
instead of just git
in all add
and commit
commands
我的问题(macOS 上的 git)已通过使用
sudo git
而不是仅git
在所有add
和commit
命令中解决