例如,我已经从某个文件夹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.
我两次都写相同的命令,但是第二次我出错。
答案 0 :(得分:0)
无论在a
或b
中,还是在与同一远程存储库连接的任何其他存储库中,请遵循以下过程进行拉和推。
# 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:master
和master
避免隐藏的问题。例如,如果碰巧有一个错误创建的引用refs/master
,则git pull origin master
将会获取refs/master
而不是refs/heads/master
。
对于git commit
,您需要定义一个函数来自动生成提交消息。
在git pull
之后,可能存在冲突,需要处理。