我最近接手了一个项目,该项目在 GitHub 上托管了一个 Git 存储库,并在生产服务器上运行。
但是,服务器上的代码不是从存储库克隆的,没有 .git 文件,并且与存储库中的代码不同。
我想做的是将生产代码作为新分支添加到现有存储库中。我怎样才能做到这一点?
...但是,服务器上的代码不是从存储库克隆的,没有 .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"
Run Code Online (Sandbox Code Playgroud)
现在,一旦它是 git 存储库,就将远程添加到存储库。git 可以有多个遥控器。
# add the repository URL
git remote add origin <git hub url>
# "download" all changes from the repository
git fetch --all --prune
Run Code Online (Sandbox Code Playgroud)
此时,您在本地分支中拥有所有更改,并且文件系统上拥有所有原始存储库代码。现在你必须将 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
Run Code Online (Sandbox Code Playgroud)
就我而言,我遇到了冲突,自从您处理原始代码以来,您也会遇到这些冲突。解决这些冲突并提交,您就可以开始了。