git 强制我的本地 master 成为 origin/master

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16103810/
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-10 15:59:43  来源:igfitidea点击:

Force my local master to be origin/master

gitgithubbranch

提问by Andiih

I've let master and origin/master get stuck in the sidelines, and am no longer interested in the changes on that branch.

我让 master 和 origin/master 被卡在了一边,并且不再对那个分支的变化感兴趣。

I followed these instructions to get my local master pointing to the right place Make the current git branch a master branch

我按照这些说明让我的本地 master 指向正确的地方 Make the current git branch a master branch

 git checkout better_branch
 git merge --strategy=ours master    # keep the content of this branch, but record a merge
 git checkout master
 git merge better_branch             # fast-forward master up to the merge

which worked fine except git status gives

除了 git status 给出之外,它工作得很好

C:\data\localprojects\Beko2011Azure [master]> git status

# On branch master
# Your branch and 'origin/master' have diverged,
# and have 395 and 2 different commits each, respectively.
#
nothing to commit, working directory clean

so how do I now persuade origin/master (github) to reflect my master. Anything orphaned on origin/master can be safely abandoned.

那么我现在如何说服 origin/master (github) 来反映我的主人。任何在 origin/master 上孤立的东西都可以安全地放弃。

回答by eckes

To have origin/masterthe same as master:

origin/master一样的master

git push -f origin master:master

Discussion on the parameters:

参数讨论:

  • -fis the forceflag. Normally, some checks are being applied before it's allowed to push to a branch. The -fflag turns off all checks.

  • originis the name of the remote where to push (you could have several remotes in one repo)

  • master:mastermeans: push my local branch masterto the remote branch master. The general form is localbranch:remotebranch. Knowing this is especially handy when you want to delete a branch on the remote: in that case, you push an empty local branch to the remote, thus deleting it: git push origin :remote_branch_to_be_deleted

  • -f旗。通常,在允许推送到分支之前会应用一些检查。该-f标志关闭所有检查。

  • origin是推送到哪里的遥控器的名称(您可以在一个 repo 中拥有多个遥控器)

  • master:master意思是:将我的本地分支推master送到远程分支master。一般形式是localbranch:remotebranch。当您想删除远程上的分支时,知道这一点特别方便:在这种情况下,您将一个空的本地分支推送到远程,从而将其删除:git push origin :remote_branch_to_be_deleted

A more elaborate description of the parameters could be found with man git-push

可以找到更详细的参数描述 man git-push



Opposite direction:If you want to throw away all your changes on masterand want to have it exactly the same as origin/master:

相反的方向:如果您想丢弃所有更改master并希望它与以下完全相同origin/master

git checkout master
git reset --hard origin/master