我无法将另一个文件夹中的另一个文件推送到我的github存储库中

时间:2019-08-01 00:55:06

标签: git github

例如,我已经从某个文件夹a.html推送了一个文件a,但是,当我尝试从另一个文件夹index.html推送另一个文件b时,通过这种方式

git init
git add index.html
git remote add origin #link of my repository
git push -u origin master

我有这样的东西

To https://github.com/NavasardianMichael/input.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to '//link to my repository'
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.

我两次都写相同的命令,但是第二次我出错。

1 个答案:

答案 0 :(得分:0)

无论在ab中,还是在与同一远程存储库连接的任何其他存储库中,请遵循以下过程进行拉和推。

# initialize the repo
git init
git remote add origin #link of my repository

# change, add and commit
git add <paths>
git commit -m'$(msg_generator)'

# update before push
git pull origin --rebase refs/heads/master:refs/heads/master

# push
git push origin refs/heads/master:refs/heads/master

这些命令似乎在脚本中使用,因此使用--rebase代替-r来提高可读性,并使用refs/heads/master:refs/heads/master代替master:mastermaster避免隐藏的问题。例如,如果碰巧有一个错误创建的引用refs/master,则git pull origin master将会获取refs/master而不是refs/heads/master

对于git commit,您需要定义一个函数来自动生成提交消息。

git pull之后,可能存在冲突,需要处理。