将git repo中的分支替换为具有更改历史记录的另一个分支

时间:2016-12-12 08:51:50

标签: git github

例如,我有一个名为 Parser 的git仓库,其分支名为生产。 然后,有一个名为 ReParser 的回购,带有分支。

我需要将 Parser / Production 替换为 Reparser / master ,包括文件和提交历史记录。我怎么能这样做?

1 个答案:

答案 0 :(得分:2)

转到Parser repo。

$ git add remote reparser <reparser/repo/url>  # add a new remote named reparser
$ git fetch reparser                         # sync with 'reparser'

$ git checkout master                        # checkout to master
$ git branch -D Production                   # delete existing local 'production' branch
$ git checkout -b Production                 # create and checkout 'new production'

$ git pull reparser master                   # replace parser/Production with reparser/master
$ git push -f origin HEAD                    # force push to remote Production of Parser