2017-04-12 73 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

相關問題