无法推进GIT,但最新的反弹

时间:2013-02-04 17:48:16

标签: git

任何人都可以解释我的存储库的状态吗?我不能推,因为服务器上有我没有的变化,但我不能反驳,因为git告诉我没有新的变化。

$ git branch
* master

$ git push origin master
To git@github.com:asdf.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com: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 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重置,然后合并分支,我仍然无法推送。

$ 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)

现在,如果我resetpull,我会看到一个新的提交。为什么fetch origin master首先没有找到这个新提交?如何确保我的存储库表示源是最新的?似乎我需要有一个成功的拉动才能使原点更新。

2 个答案:

答案 0 :(得分:3)

问题似乎在于git fetch使用不当:git fetch origin mastermaster作为refspec读取,并且不像常规提取。更具体地说,它只是让FETCH_HEAD指向远程master

如果在没有refspec的情况下使用fetch,则会使用+refs/heads/*:refs/remotes/origin/*作为默认值来更新所有引用origin/*

请尝试git fetch origingit fetch

以下是有关详细信息的好文档:https://git-scm.com/book/th/ch9-5.html

答案 1 :(得分:1)

当你checkout -b时,你就完成了新的分支。所以你已经重置并合并到备份。试试这种方式:

$ git branch backup
$ git fetch origin master
$ git reset origin/master --hard
$ git merge backup
$ git push origin master

如果您使用的是Windows,请查看posh-git以获取您的命令行状态的可视反馈(使用PowerShell)。

如果您使用的是Mac或Linux,请在github上查看一些dot-files个repo以获得类似的功能。