请教一下,我在GitHub上fork了别人的一个项目,并且自己做了一些改动。现在别人的那个项目有更新了,我怎么把自己fork过来的那个版本更新到最新的代码?
|
1
我想把自己fork的那个版本更新到最新版,然后再在上面做修改。我该怎么弄啊?
|
|
darkyoungNov 29, 2011
2
把别人的版本做一个branch,然后merge过来
|
|
icyflashNov 29, 2011
3
|
|
ywjnoNov 29, 2011
4
用remote从远端获取最新代码,然后本地merge一下就ok了
|
|
zhen9aoNov 29, 2011
5
从别人项目那里利用remote将更新pull过来,然后再利用remote将更新了的代码push到自己的库中
|
|
benzherenNov 30, 2011
6
推荐一个适合和github一起用的好工具: http://defunkt.io/hub/
|
|
ashchanNov 30, 2011
7
假设你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。 |
|
ashchanNov 30, 2011
8
如果要先更新再修改提交,并假设本地已经做了修改,则第一步不变,加原始库为upstream(名字你随便取,无所谓的,只要不是origin就行)
$ git stash # 把你的修改先暂存下来,假设没有commit过,有的话会复杂一点,就不如直接用上面的方法 $ git pull upstream/master # 既然没有commit过,这里会直接fast forward $ git stash pop stash@{1} # 把暂存的修改拿回来 $ git add . & git commit -m "commit msg" 最后两步一样。 |
|
ashchanNov 30, 2011
9
如果不打算向原项目提pull request,只是想不断更新他的,就一直用第一种方式。不过随着你自己的修改越来越多,起冲突的机会会越来越多。hope this helps.
|
|
11
谢谢各位的帮忙,已经搞好了!
|
|
rikuJan 5, 2012
12
我觉得用 git rebase 是不是更好点?
|