简体   繁体   English

Github如何更新分叉的repo,和新分叉的完全一样

[英]Github how to update the forked repo, entirely the same as newly forked

Many days ago, I forked the Airflow repo and I modified a little then submitted a PR.很多天前,我 fork 了 Airflow repo 并修改了一些然后提交了 PR。

But today, I want to submit another PR, so I need to re-fork the latest Airflow source code, and discard all the changes in my repo.但是今天又想再提交一个PR,所以需要re-fork最新的Airflow源码,把repo里面的改动全部丢掉。

A clumsy way is to delete my repo, then fork the official repo again.一个笨拙的方法是删除我的 repo,然后再次 fork 官方 repo。 Actually, after searching, it doesn't have to delete and fork.实际上,搜索后,它不必删除和分叉。

What I tried:我试过的:

$ 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

In this way, however, I have to git commit before git push origin master , so there is an additional commit showing in my repo.但是,通过这种方式,我必须在git push origin master之前git commit ,因此在我的 repo 中显示了一个额外的提交。

My question is how can I update the forked repo, just like a newly forked repo.我的问题是如何更新分叉的 repo,就像新分叉的 repo 一样。

Reference参考

How to synchronize fork with original GitHub project? 如何将 fork 与原始 GitHub 项目同步? How do I update a GitHub forked repository? 如何更新 GitHub 分叉存储库?

you need to pull the changes from upstream, rebase option will put your changes on top of synced changes from upstream.您需要从上游pull更改, rebase选项会将您的更改置于上游同步更改之上。

pull will fetch and merge the changes automatically however you may have conflicts in some files that were out of sync or outdated. pull将自动fetchmerge更改,但是您可能会在某些不同步或过时的文件中发生冲突。

$ git pull upstream --r

update your fork with your changes + synched changes from upstream , sometimes you may have situation where there are some changes in your remote fork that are not in your local git.使用来自upstream更改 + 同步更改来更新您的分支,有时您可能会遇到远程分支中有一些不在本地 git 中的更改的情况。 in this case you can pull such changes from your fork and merge locally or use force or -f option to force pushing and overwriting your fork.在这种情况下,您可以从您的 fork 中pull此类更改并在本地合并,或者使用force-f选项来强制推送和覆盖您的 fork。

$ git push origin branch

Now you can safely open PR from github itself.现在您可以安全地从 github 本身打开 PR。

I hope this helps you out, if not please feel free to leave comment and I would be happy to help more and update my answer我希望这对您有所帮助,如果没有,请随时发表评论,我很乐意提供更多帮助并更新我的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM