不能添加到(新)git-repository

时间:2017-07-17 09:36:37

标签: git bitbucket

我是git的新手,只是想按照bitbucket的说明操作。我试图将文件添加到最近创建的git仓库。

这就是我所做的:

cd myrepo
git init
git remote add origin https://pathfrombitbucket.org/myaccountname/myrepo.git
git push -u origin master
git add .
git commit -m "initial commit"

但到目前为止,除了.gitignore文件之外,其他任何内容都没有出现在网页界面中。 gitignore文件之前已经使用了很多次,我们有多个现有的回购。

如何从这里继续调查?

编辑1:

@ Lorenzo / Mateus / Andus ......以及其他所有人:):

当我再次推送时,我收到错误消息

! [rejected]        master -> master (fetch first)
    error: failed to push some refs to 'https://path-from_git/myrepo.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

编辑2 试图拉

>git pull  'https://path-from_git/myrepo.git'

 * branch            HEAD       -> FETCH_HEAD
fatal: refusing to merge unrelated histories

编辑3 没有理解最后的消息(来自编辑2)所以我删除了回购并重新开始。

3 个答案:

答案 0 :(得分:0)

在添加文件之前使用git pushGit add只是存储文件,并通过提交将它们提交给本地HEAD。要在回购中查看它们,您必须使用git push将本地HEAD推送到远程仓库。

这里是周期(来自rogerdudler's great tutorial):

git trees

如您所见,在提交文件时,它们仍在您的本地计算机上,而不在远程仓库中。

回复您的修改:

如果使用IntelliJ或VS Code(或类似)之类的IDE,则只需从远程源提取更改并将其与本地文件合并即可。在解决本地HEAD和远程HEAD之间的所有冲突之前,您无法推送。 Rogerdudler's tutorial显示了如何使用git shell(在update& merge下),但我觉得这很麻烦。

由于您刚刚创建了回购邮件,因此只需git clone即可,而且您已经了解并且不必合并所有更改。

答案 1 :(得分:0)

收到错误消息后,AnDus建议我再做一次拉,谢谢!

我做了这个,但收到了另一条错误消息"拒绝合并不相关的历史记录"。我不知道这意味着什么,也不知道为什么几乎不可能将文件添加到全新的存储库中。但我找到了旗帜

git pull origin master --allow-unrelated-histories

这使拉动请求通过,我可以做第二次推动。

虽然,git似乎忽略了我的.gitignore文件:/

答案 2 :(得分:-1)

提交后,您应该再次执行git push。 然后代码更改应该显示在远程存储库中。