回答

收藏

如何更新或同步 GitHub 上的分叉存储库?

技术问答 技术问答 297 人阅读 | 0 人回复 | 2023-09-11

我分叉了一个项目,应用了几个修复程序,并创建了一个可接受的提取请求。几天后,另一个贡献者做了另一个改变。所以我的叉子不包括这个变化。
# y7 J8 ~7 @0 u7 L, m3 k我怎样才能把零钱放在叉子里?当我有进一步的改变来做出贡献时,是否需要删除和重建我的分叉?还是有更新按钮?: Y9 g. }' h* B! o8 N  i' z
                                                               
) z. ~  N5 q% s, p) E, J    解决方案:                                                               
% G4 J' U- P3 G7 U: x0 g                                                                在分叉存储库的本地克隆中,您可以使用原始 GitHub 存储库被添加到远程中。(远程就像存储 URL 的昵称 -origin例如,它是一个。)然后你可以从上游存储库中获得所有的分支,并重新设置你的工作,以继续在上游版本中工作。以下命令可能如下:2 o, M% i( a0 q! x; _) F
    # Add the remote,call it "upstream":git remote add upstream https://github.com/whoever/whatever.git# Fetch all the branches of that remote into remote-tracking branchesgit fetch upstream# Make sure that you're on your master branch:git checkout master# Rewrite your master branch so that any commits of yours that# aren't already in upstream/master are replayed on top of that# other branch:git rebase upstream/master
    & W' |7 o5 e3 n) C- C2 O4 t
假如你不想重写 master 分支的历史记录(比如别人可能已经克隆了),所以你应该用最后一个命令代替git merge upstream/master. 但是,为了进一步发出尽可能干净的拉取请求,最好重新设置基础。% d9 }) L( j! V% d: V) K
如果你已经将你的分支重新建立在upstream/master在你的基础上,你可能需要强制把它推给你自己GitHub 分叉存储库。您将这样做:1 D: D( ~9 O* h9 C4 o1 Z
git push -f origin master您只需-f重新定位后第一次使用。
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则