谁能解释一下我的存储库的状态吗?我无法推送,因为服务器上有我没有的更改,但我无法 rebase ,因为 git 告诉我没有新的更改。
$ git branch
* master
$ git push origin master
To <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="03646a7743646a776b76612d606c6e" rel="noreferrer noopener nofollow">[email protected]</a>:asdf.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="81e6e8f5c1e6e8f5e9f4e3afe2eeec" rel="noreferrer noopener nofollow">[email protected]</a>:asdf.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git fetch origin master
From github.com:knowitall/nlptools
* branch master -> FETCH_HEAD
$ git rebase origin master
Already on 'master'
Your branch is ahead of 'origin/master' by 3 commits.
Current branch master is up to date.
$ git pull origin master
它建议的 merge 是空的。
Merge branch 'master' of github.com:knowitall/nlptools
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
如果我创建一个分支,使用 origin/master 重置,然后 merge 该分支,我仍然无法推送。
$ git checkout -b backup
$ git checkout master
$ git fetch origin master
$ git reset origin/master --hard
$ git merge backup
$ git push origin master
! [rejected] master -> master (non-fast-forward)
现在,如果我重置
并 pull
,我会看到一个新的提交。为什么 fetch origin master
一开始没有找到这个新的提交?如何确保我的存储库来源表示是最新的?看来我需要成功 pull 才能使源保持最新。
最佳答案
问题似乎在于 git fetch
用法不当:git fetch origin master
将 master
读取为 refspec,并且行为不像定期获取。更具体地说,它只是使 FETCH_HEAD
指向远程 master
。
当在没有引用规范的情况下使用fetch
时,它使用+refs/heads/*:refs/remotes/origin/*
作为默认值,更新所有引用起源/*
。
尝试使用 git fetch origin
或 git fetch
来代替。
这里有一个关于它的很好的文档以获取更多详细信息:https://git-scm.com/book/th/ch9-5.html
关于git - 无法 push GIT,但 rebase 为最新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14692425/