2017-04-12 58 views
0

我最近接管了一个项目,该项目有一个托管在GitHub上的Git存储库,并且正在生产服务器上运行。
但是,服务器上的代码没有从repo克隆,没有.git文件,并且与存储库中的代码不同。将代码库的不同副本添加到现有的git存储库

我想要做的是将生产代码添加到现有的回购作为一个新的分支。我怎样才能做到这一点?

回答

1

......然而,在服务器上的代码是不是克隆从回购,没有一个git的文件,并从信息库中的代码不同

我想什么要做的是将生产代码添加到现有的回购作为一个新的分支。

它很简单。

在你的代码文件夹中您的服务器使其成为一个Git项目

# convert the folder to a git repository 
git init 

# commit your local changes to a new branch 
git checkout -b <branch name> 
git add . 
git commit -m "Initial commit" 

现在,一旦它的一个git回购远程添加到库中。 git可以有多个遥控器。

# add the repository URL 
git remote add origin <git hub url> 

# "download" all changes from the repository 
git fetch --all --prune 

在这一点上你有你在当地的分支机构的所有更改,你有你的文件系统上的原始回购代码。现在,你必须在2

# choose the desired branch 
git branch -a 

# merge the desired branch code into your branch. 
# since its unrelated history you can simply merge it you have 
# to use cherry-pick 
git rev-list --reverse master | git cherry-pick -n --stdin 

结合我的情况,我有,你还会因为你处理过的原代码有冲突。修复这些冲突并提交,然后您就可以开始了。

enter image description hereenter image description here

相关问题