我最近接手了一个项目,该项目有一个在GitHub上托管的Git存储库,并且正在生产服务器上运行。
但是,服务器上的代码未从repo克隆,没有.git文件,并且与存储库中的代码不同。
我想要做的是将生产代码作为新分支添加到现有仓库。我怎么能这样做?
答案 0 :(得分:1)
...但是,服务器上的代码是未克隆来自repo,没有.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 repo将一个遥控器添加到存储库。 git可以有多个遥控器。
# add the repository URL
git remote add origin <git hub url>
# "download" all changes from the repository
git fetch --all --prune
此时,您在本地分支中拥有所有更改,并且您的文件系统上包含所有原始repo代码。现在你必须结合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
在我的情况下,我有冲突,自从你处理原始代码以来,你也会遇到冲突。修复这些冲突并提交,你就可以开始了。