git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
zerotty
V2EX  ›  git

请教一个GitHub的问题?

  •  
  •   zerotty · Nov 29, 2011 · 7821 views
    This topic created in 5284 days ago, the information mentioned may be changed or developed.
    请教一下,我在GitHub上fork了别人的一个项目,并且自己做了一些改动。现在别人的那个项目有更新了,我怎么把自己fork过来的那个版本更新到最新的代码?
    12 replies    1970-01-01 08:00:00 +08:00
    zerotty
        1
    zerotty  
    OP
       Nov 29, 2011
    我想把自己fork的那个版本更新到最新版,然后再在上面做修改。我该怎么弄啊?
    darkyoung
        2
    darkyoung  
       Nov 29, 2011
    把别人的版本做一个branch,然后merge过来
    icyflash
        3
    icyflash  
       Nov 29, 2011
    ywjno
        4
    ywjno  
       Nov 29, 2011
    用remote从远端获取最新代码,然后本地merge一下就ok了
    zhen9ao
        5
    zhen9ao  
       Nov 29, 2011
    从别人项目那里利用remote将更新pull过来,然后再利用remote将更新了的代码push到自己的库中
    benzheren
        6
    benzheren  
       Nov 30, 2011
    推荐一个适合和github一起用的好工具: http://defunkt.io/hub/
    ashchan
        7
    ashchan  
       Nov 30, 2011
    假设你fork的项目原始地址是http://github.com/abc/rep.git, 你自己的是http://github.com/you/rep.git

    $ git add remote upstream http://github.com/abc/rep.git # 你本地的origin应该跟了自己的remote,前且假设当前本地branch是master。
    $ git fetch upstream
    $ git merge upstream/master # merge可能会有冲突,手工解决掉并commit
    $ git push origin/master # push到你自己的fork上

    然后向原始项目提交一个pull request。
    ashchan
        8
    ashchan  
       Nov 30, 2011
    如果要先更新再修改提交,并假设本地已经做了修改,则第一步不变,加原始库为upstream(名字你随便取,无所谓的,只要不是origin就行)

    $ git stash # 把你的修改先暂存下来,假设没有commit过,有的话会复杂一点,就不如直接用上面的方法
    $ git pull upstream/master # 既然没有commit过,这里会直接fast forward
    $ git stash pop stash@{1} # 把暂存的修改拿回来
    $ git add . & git commit -m "commit msg"

    最后两步一样。
    ashchan
        9
    ashchan  
       Nov 30, 2011
    如果不打算向原项目提pull request,只是想不断更新他的,就一直用第一种方式。不过随着你自己的修改越来越多,起冲突的机会会越来越多。hope this helps.
    kaichen
        10
    kaichen  
    PRO
       Nov 30, 2011
    赞 @ashchan 非常详细的解释

    这个问题不是Github的问题,其实是个Git的用法问题。
    zerotty
        11
    zerotty  
    OP
       Nov 30, 2011
    谢谢各位的帮忙,已经搞好了!
    riku
        12
    riku  
       Jan 5, 2012
    我觉得用 git rebase 是不是更好点?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2638 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 84ms · UTC 15:08 · PVG 23:08 · LAX 08:08 · JFK 11:08
    ♥ Do have faith in what you're doing.