如何在我在github.com上创建的项目之上重播对本地Git存储库的提交?
是的,我知道我应该从一开始就对项目进行分叉,但这就是我现在所处的情况. :)
我在本地计算机上有一个本地Git存储库,其中包含我的博客,该博客具有几个月的提交历史.最初,我只是从存储库下载文件 http://github.com/mojombo/mojombo.github.com ,我继续使用我本地的Git存储库,第一次提交看起来像是mojombo存储库中的最新文件.
I have a local Git repository that contains my blog, on my local computer, that has several months of commit history. Originally, I simply downloaded the files from the repository http://github.com/mojombo/mojombo.github.com, and I continued on with my local Git repository, with the first commit looking like the latest files from mojombo's repository.
我现在想分叉该项目,并在其顶部重播我的本地Git存储库提交,因此看起来我从一开始就分叉了该项目,然后将其推回到我的mojombo存储库的分叉版本中,在我的GitHub帐户上:
I would now like to fork the project and have my local Git repository commits be replayed on top of it, so it looks like I forked the project from the beginning, and then pushed it back to my forked version of mojombo's repository, on my GitHub account:
http://github.com/program247365/mojombo.github.com
所以历史也许会像这样:
So perhaps the history would then look like this:
mobjombo repository: 1---2---3----23
\
my blog repository commits: 24---25---
我可以完全使用哪些Git命令来做到这一点?
What Git commands can I use exactly to do this?
我查看了这个问题.我是否需要将mojombo的存储库添加为我的项目的远程站点,然后将其拉入,合并,解决冲突,然后推送到GitHub上的分叉项目?
I've looked at this question. Will I have to add mojombo's repository as a remote to my project, and then pull it in, merge, resolve conflicts, and then push to my forked project on GitHub?
当我尝试git pull
时,出现以下错误:
When I tried git pull
it gave me the following error:
$ git pull grid master:master
! [rejected] master -> master (non fast forward)
在我的特定情况下,看来git rebase
是我的理想之选,如此处的步骤所示:
In my particular case, it seemed that git rebase
was the way to go for me, as shown by the steps here:
#Clone my forked project from github
git clone git@github.com:program247365/mojombo.github.com.git
#Add my repo as a remote repo, with the alias 'grid'
git remote add grid "path/to/remote/gitrep/with/all/history/unrelated/to/mojombo/"
#Rebase my commits on top of mojombo's
git rebase master grid/master
#Switch to the local master branch
git checkout master
#Call up my mergetool via git, to start rectifying the conflicts that emerge between my repo, and mojombo's
git mergetool
#Push my rebased/combined repo back to Github.com
git push github