Can';不要推GIT,而是重新设置最新的基址

Can';不要推GIT,而是重新设置最新的基址,git,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:a

有人能解释一下我的存储库的状态吗?我不能推送,因为服务器上有我没有的更改,但我不能重新设置基础,因为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)

现在,如果我
reset
pull
,我会看到一个新的提交。为什么
fetch origin master
一开始没有找到这个新提交?如何确保我的源代码存储库表示是最新的?看来我需要成功地拉取才能使源代码更新。

当您
签出-b
时,您就完成了新分支。所以您已经重置并合并到备份上了。试着这样做:

$ git branch backup
$ git fetch origin master
$ git reset origin/master --hard
$ git merge backup
$ git push origin master
如果您使用的是Windows,请注意在命令行(使用powershell)上获取您的状态的可视反馈


如果您在Mac或Linux上,请在github上签出一些
点文件
repo以获得类似的功能。

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

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

尝试
git fetch origin
git fetch


这里有一个很好的文档,可以了解更多详细信息:

您所说的“完成新分支”是什么意思?当您结帐时,您会更改分支。在示例代码中,您没有在之后切换回master。