git 如何修复“您的分支在 1 次提交之前领先于 'origin/master'。”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50112363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:06:59  来源:igfitidea点击:

How to fix "Your branch is ahead of 'origin/master' by 1 commit."?

gitgithub

提问by Alex

I have a local checkout of a repository of a fork on my computer (from github). So on github I created a fork, and checked that out.

我在我的计算机上有一个 fork 存储库的本地结帐(来自 github)。所以在 github 上我创建了一个 fork,并检查了它。

Now I want the local checkout to be the same as the original github repository (the one I created the fork from). I added that original repo to my local repo (with the name 'orig') and did the following:

现在我希望本地结帐与原始 github 存储库(我从中创建 fork 的存储库)相同。我将该原始存储库添加到我的本地存储库(名称为“orig”)并执行以下操作:

git pull orig master

However, git statusshows me

然而,git status给我看

On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

Also git diffor git diff origin/mastershows nothing.

git diff或不git diff origin/master显示任何内容。

Is there a way to make the local checkout equal to what is in the original master branch (without removing the local repo, the github fork, forking anew, checking out anew...)?

有没有办法使本地结帐等于原始主分支中的内容(不删除本地存储库、github 分支、重新分叉、重新结帐......)?

I do not care if there any uncommited changes or anything. I want the local checkout to be equal to the original repo...

我不在乎是否有任何未提交的更改或任何内容。我希望本地结帐等于原始回购...

回答by VonC

You can reset your local branch to the one in orig, then push to your fork

您可以将本地分支重置为 orig 中的分支,然后推送到您的叉子

git checkout master
git reset --hard origin/master
git push --force origin master

Your local repo and fork master branch will be the same as the original repo.

您的本地 repo 和 fork master 分支将与原始 repo 相同。

If need clean: git clean -f -d

如果需要清理: git clean -f -d

回答by Deepak

Use the command below :

使用以下命令:

git reset --hard HEAD

git reset --hard HEAD