![](/img/trans.png)
[英]How to make a GitHub repo the same as if it was originally forked from another repo?
[英]Github how to update the forked repo, entirely the same as newly forked
很多天前,我 fork 了 Airflow repo 并修改了一些然后提交了 PR。
但是今天又想再提交一个PR,所以需要re-fork最新的Airflow源码,把repo里面的改动全部丢掉。
一个笨拙的方法是删除我的 repo,然后再次 fork 官方 repo。 实际上,搜索后,它不必删除和分叉。
$ git remote add upstream <original-repo-url>
$ git fetch upstream # update local with upstream
$ git diff HEAD..upstream/master # see diffs between local and upstream/master (if there is no diff then both are in sync)
$ git pull upstream master # pull upstream's master into local branch
$ git push origin HEAD # push to your forked repo's remote branch
但是,通过这种方式,我必须在git push origin master
之前git commit
,因此在我的 repo 中显示了一个额外的提交。
我的问题是如何更新分叉的 repo,就像新分叉的 repo 一样。
您需要从上游pull
更改, rebase
选项会将您的更改置于上游同步更改之上。
pull
将自动fetch
并merge
更改,但是您可能会在某些不同步或过时的文件中发生冲突。
$ git pull upstream --r
使用来自upstream
更改 + 同步更改来更新您的分支,有时您可能会遇到远程分支中有一些不在本地 git 中的更改的情况。 在这种情况下,您可以从您的 fork 中pull
此类更改并在本地合并,或者使用force
或-f
选项来强制推送和覆盖您的 fork。
$ git push origin branch
现在您可以安全地从 github 本身打开 PR。
我希望这对您有所帮助,如果没有,请随时发表评论,我很乐意提供更多帮助并更新我的答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.