简体   繁体   English

当前代码库的微妙 git 合并

[英]Delicate git merge of current codebase

I got in some weird issue here and before do any actions I would like to get some advices.我在这里遇到了一些奇怪的问题,在采取任何行动之前我想得到一些建议。

We have a legacy project that the company wants to add it to git. My colleague already added git repo and commit the legacy code into it.我们有一个遗留项目,公司希望将其添加到 git。我的同事已经添加了 git 存储库并将遗留代码提交到其中。 But I have doubts that it is not quite in sync with the code on the live system.但我怀疑它与实时系统上的代码不太同步。 As we plan to use git in future, now we need to add/sync the current code from live server, to the git repo with current code that is already on the repo.由于我们计划在未来使用 git,现在我们需要将当前代码从实时服务器添加/同步到 git 仓库,其中当前代码已经在仓库中。 Live server is not handled by git so far.到目前为止,git 未处理实时服务器。 But will be, once we perform that sync.但是,一旦我们执行该同步,就会。 I need to make sure, that code from the live server will go on git, omitting any changed files that are already been added to git repo and will continue to work as before git. After then we will add that git to staging server, where we will sync with git and test and if all is OK - will just sync the live server.我需要确保,来自实时服务器的代码将在 git 上运行 go,省略任何已添加到 git 回购中的更改文件,并将继续像之前 git 一样工作。之后我们将把 git 添加到暂存服务器,其中我们将与 git 同步并进行测试,如果一切正常 - 将只同步实时服务器。

Hope this scenario is explained well enough, but if not - please, let me know and I`ll shed more lights on it.希望这个场景得到足够好的解释,但如果没有 - 请告诉我,我会详细说明。

Thanks in advance.提前致谢。

Live server to continue to work with original code, while we get in sync the whole code base, spread on several servers.实时服务器继续使用原始代码,同时我们同步整个代码库,分布在多个服务器上。

I need to make sure, that code from the live server will go on git, omitting any changed files that are already been added to git repo and will continue to work as before git.我需要确保来自实时服务器的代码将在 git 上为 go,省略任何已添加到 git 存储库的更改文件,并将继续像 git 之前一样工作。

That means you need:这意味着你需要:

  • to get a local copy of the live server current code获取实时服务器当前代码的本地副本
  • to reset your Git repository to its first commit (before any changes)将您的 Git 存储库重置为其第一次提交(在任何更改之前)
  • to add your server code to that Git repository, in a dedicated branch将您的服务器代码添加到专用分支中的 Git 存储库
  • finally, to merge that branch to your current branch (which will preserve any recent change, but will update non-changed files with the server code from the dedicated branch)最后,将该分支合并到您当前的分支(这将保留所有最近的更改,但会使用专用分支中的服务器代码更新未更改的文件)

That is:那是:

cd /path/to/local/repository
git switch -c server_sync <your Initial commit before any changes>
git add --work-tree=/path/to/local/copy/of/server/codebase .
git commit -m "server sync"
git switch main
git merge server_sync

Actually, from the comments :实际上,从评论

We made our repo, with last stage code from vendor's repo and now I have to make sure it is the same as on the live server, prioritizing the code from the server我们使用供应商回购的最后阶段代码制作了我们的回购,现在我必须确保它与实时服务器上的相同,优先考虑来自服务器的代码

Then it is simpler: you don't need a dedicated branch:然后就更简单了:你不需要专门的分支:

cd /path/to/local/repository
git switch main
git add --work-tree=/path/to/local/copy/of/server/codebase .
git commit -m "server sync"
git push

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM