本地代码与远程存储库不同步
Local code is not in sync with Remote Repository
我们面临以下问题,我们的本地代码与远程存储库不同步。
我们最近将一段代码(在 Git 早期未维护)推送到 Git Repository.After 将本地副本推送到 Git 我们意识到的存储库,即我们在本地机器的另一个路径中有一些更新的本地副本,我们不会尝试将这些东西推送到远程存储库。在推动更改时,我们遇到了以下问题。
$ git push origin master
To https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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 branch -r
origin/master
$ git pull origin master
From https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg
* branch master -> FETCH_HEAD
Already up to date.
$ git push origin master
To https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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 --rebase origin master
From https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg
* branch master -> FETCH_HEAD
Already up to date.
fatal: It seems that there is already a rebase-apply directory, and
I wonder if you are in the middle of another rebase. If that is the
case, please try
git rebase (--continue | --abort | --skip)
If that is not the case, please
rm -fr ".git/rebase-apply"
and run me again. I am stopping in case you still have something valuable there.
$ git pull origin master
From https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
很可能一个简单的 git pull
就能解决这个问题:
# from master
git pull origin master
但请注意,这可能会导致本地合并冲突,您必须解决(后跟 git commit
)。这里的另一种选择是使用变基策略进行拉动:
git pull --rebase origin master
这将保留您的本地提交,但它仍然可能导致发生合并冲突。
编辑:
错误信息refusing to merge unrelated histories
表示您的本地仓库与远程仓库不一样。也就是说,您的本地存储库包含一些项目,而不是您指向的远程项目。这可能是因为远程历史记录被更改,或者因为您在本地配置错误。
我们面临以下问题,我们的本地代码与远程存储库不同步。
我们最近将一段代码(在 Git 早期未维护)推送到 Git Repository.After 将本地副本推送到 Git 我们意识到的存储库,即我们在本地机器的另一个路径中有一些更新的本地副本,我们不会尝试将这些东西推送到远程存储库。在推动更改时,我们遇到了以下问题。
$ git push origin master
To https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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 branch -r
origin/master
$ git pull origin master
From https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg
* branch master -> FETCH_HEAD
Already up to date.
$ git push origin master
To https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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 --rebase origin master
From https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg
* branch master -> FETCH_HEAD
Already up to date.
fatal: It seems that there is already a rebase-apply directory, and
I wonder if you are in the middle of another rebase. If that is the
case, please try
git rebase (--continue | --abort | --skip)
If that is not the case, please
rm -fr ".git/rebase-apply"
and run me again. I am stopping in case you still have something valuable there.
$ git pull origin master
From https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
很可能一个简单的 git pull
就能解决这个问题:
# from master
git pull origin master
但请注意,这可能会导致本地合并冲突,您必须解决(后跟 git commit
)。这里的另一种选择是使用变基策略进行拉动:
git pull --rebase origin master
这将保留您的本地提交,但它仍然可能导致发生合并冲突。
编辑:
错误信息refusing to merge unrelated histories
表示您的本地仓库与远程仓库不一样。也就是说,您的本地存储库包含一些项目,而不是您指向的远程项目。这可能是因为远程历史记录被更改,或者因为您在本地配置错误。