如何在分支存储库中将git master分支重置为上游分支? [英] How do I reset the git master branch to the upstream branch in a forked repository?

查看:136
本文介绍了如何在分支存储库中将git master分支重置为上游分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完全弄乱了我的git repo的master分支.

I've completely messed up the master branch of my forked git repo.

我想用上游master回购的内容完全重置推送到我的fork的master分支.我没有兴趣保留任何主分支更改或历史记录.

I want to completely reset the master branch that was pushed to my fork with the contents of the upstream master repo. I have no interest in retaining any master branch changes or history.

最简单的方法是从上游项目中删除我的分叉的仓库和仓库.但是,我在其他不想丢失的推送分支中工作.

The simplest approach would have been to delete my forked repo and refork from the upstream project. However, I have work in other pushed branches that I don't want to lose.

因此如何用上游主服务器重置推送的主分支?

Thus how to I reset my pushed master branch with the upstream master?

git clone https://myrepo.git
cd myrepo
git remote add upstream https://upstream.git
git fetch upstream

我应该从何处重置上游主服务器的本地和远程主服务器分支?

Where do I go from here to reset my local and remote master branches with the upstream master?

推荐答案

您可以将本地master分支重置为上游版本,并将其推送到您的存储库中.

You can reset your local master branch to the upstream version and push it to your your repository.

假设上游"是原始存储库,而起源"是您的fork:

Assuming that "upstream" is the original repository and "origin" is your fork:

# ensures current branch is master
git checkout master

# pulls all new commits made to upstream/master
git pull upstream master

# this will delete all your local changes to master
git reset --hard upstream/master

# take care, this will delete all your changes on your forked master
git push origin master --force

(您可以使用git remote add upstream /url/to/original/repo将原始存储库定义为上游".)

(You can define the original repo as "upstream" with git remote add upstream /url/to/original/repo.)

这篇关于如何在分支存储库中将git master分支重置为上游分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆