gpt4 book ai didi

git - 无法推送 GIT,但会更新到最新

转载 作者:行者123 更新时间:2023-12-02 22:14:38 24 4
gpt4 key购买 nike

任何人都可以解释我的存储库的状态吗?我无法推送,因为服务器上有我没有的更改,但我无法 rebase ,因为 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 是空的。

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)

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

最佳答案

问题似乎出在不正确的 git fetch 用法上:git fetch origin mastermaster 读取为 refspec 并且其行为不像定期获取。更具体地说,它只是让 FETCH_HEAD 指向远程 master

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

试试 git fetch origingit fetch

关于它的更多详细信息,这是一个很好的文档:https://git-scm.com/book/th/ch9-5.html

关于git - 无法推送 GIT,但会更新到最新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14692425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com