清理叉子并从上游重新启动它 [英] Clean up a fork and restart it from the upstream

查看:99
本文介绍了清理叉子并从上游重新启动它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我分叉了一个存储库,然后我做了一些修改,看起来我弄糟了一切。

我希望从头开始重新使用当前的上游/主作为工作的基础。

我应该重新绑定我的存储库还是删除它?

解决方案

最简单的解决方案是(使用'上游'作为引用原始回购分录的远程名称):

  git remote add upstream / url / to / original / repo 
git fetch upstream
git checkout master
git reset --hard upstream / master
git push origin master --force

(类似于对 push --force 。

所以你必须取消保护 master 首先(请参阅下图),然后


I have forked a repository, then I made some changes and it looks like I've messed up everything.

I wish to start it again from scratch, using the current upstream/master as the base for my work.
Should I rebase my repository or delete it at all?

解决方案

The simplest solution would be (using 'upstream' as the remote name referencing the original repo forked):

git remote add upstream /url/to/original/repo
git fetch upstream
git checkout master
git reset --hard upstream/master  
git push origin master --force 

(Similar to this GitHub page, section "What should I do if I’m in a bad situation?")

Be aware that you can lose changes done on the master branch (both locally, because of the reset --hard, and on the remote side, because of the push --force).

An alternative would be, if you want to preserve your commits on master, to replay those commits on top of the current upstream/master.
Replace the reset part by a git rebase upstream/master. You will then still need to force push.
See also "What should I do if I’m in a bad situation?"


A more complete solution, backing up your current work (just in case) is detailed in "Cleanup git master branch and move some commit to new branch".

See also "Pull new updates from original GitHub repository into forked GitHub repository" for illustrating what "upstream" is.


Note: recent GitHub repos do protect the master branch against push --force.
So you will have to un-protect master first (see picture below), and then re-protect it after force-pushing).

这篇关于清理叉子并从上游重新启动它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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