我在stackoverflow上查看了很多类似的问题答案,但似乎没有解决我的问题。我做了很多更改,并有一个庞大的提交历史记录,目前我还可以接受。一切都正常工作后,我发起了一个pull request,并将其合并到了我从中fork的仓库中。但是我的fork仍然比原始仓库多了X个提交,我无法重置这个提交计数器。我尝试过rebase、reset和其他所有我能找到的方法,但仍然看到这个:here。如何使一切恢复正常?到目前为止,我只在自己的项目中使用过git,git的某些设计让我感到困惑。
git checkout master // --> will move to origin master
git fetch upstream // --> pulls all branches from mainline/remote master
git reset --hard upstream/master // ==> reset your origin local code with latest remote master
git push --force // ==> update with remote with your local updates
master
与上游的master
处于相同的位置:git fetch --all
git push --force upstream/master:master
一旦你这样做,它可能会抱怨你本地的主分支比上游的分支超前/落后。如果你执行git pull [--rebase]
,你只是将你的本地历史记录与上游的历史记录合并/变基,并且你仍然会保持领先。所以你可以将你的本地master
分支移动到你的派生库的master
分支:
git stash # in case of local modifications
git reset --hard origin/master
git stash pop
这样,您应该能够与上游和分叉存储库保持同步。
您还应考虑清理远程存储库,仅保留这两个(origin和upstream),因为我猜其他的只是它们的本地副本。
您可以使用git remote --verbose
检查远程存储库的URL:只需为每个不同的URL保留一个。
我也遇到了同样的问题。git 找不到上游...
% git fetch upstream
fatal: 'upstream' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我删除了我的库,重新 Fork 了一次。
git fetch --all
、git branch -vv
和git log --graph --oneline --decorate master origin/master upstream/master
的结果。 - zigarn