我有我的远程服务器、Bitbucket 存储库和我的本地存储库。当我想更改某个文件时,我会在我的本地存储库中更改它,然后是git add <file_name>
/ git commit -m "file changed"
,然后git push
是我的 Bitbucket 存储库。然后我收到以下错误:
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
然后我做git push --set-upstream origin master
并得到这些错误:
To https://bitbucket.org/user/name.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to
'https://[email protected]/user/name.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.
我不想这样做,git pull
因为我的本地存储库与 Bitbucket 存储库不同,Bitbucket 存储库用于生产,本地存储库用于开发,它们是否不同。我想要做的只是通过在本地更改它们并简单地执行git add <updated_file>
/来更新我的 Bitbucket 存储库中的单个文件git commit
。有什么办法可以做到这一点吗?
简而言之,没有git pull
.
由于 git 将计算您尝试推送的远程分支中的所有 sha-1 值是否存在于本地存储库中,然后决定是否可以推送或拒绝它。如您所见,如果您在没有 的情况下推送到远程git pull
,git 将拒绝推送。
您可以遵循两个选项:
您可以使用以下命令来实现:
git reset head~
git stash -- filename
git fetch
git reset --hard origin/master
git statsh apply
git push -u origin master
然后只有filename
推送到远程master
分支。
您可以强制将本地分支推送到master
远程master
分支git push -f origin master
或推送到新分支。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句