git - 当前代码库的精细 git merge

标签 git synchronization

我在这里遇到了一些奇怪的问题,在采取任何行动之前我想得到一些建议。

我们有一个遗留项目,公司希望将其添加到 git 中。我的同事已经添加了 git repo 并将遗留代码提交到其中。但我怀疑它与实时系统上的代码不太同步。由于我们计划将来使用 git,现在我们需要将当前代码从实时服务器添加/同步到 git 存储库,并使用存储库中已有的当前代码。到目前为止,实时服务器还不是由 git 处理的。但是,一旦我们执行同步,就会如此。我需要确保来自实时服务器的代码将在 git 上运行,忽略已添加到 git 存储库中的任何已更改文件,并将继续像以前一样工作。之后,我们将该 git 添加到登台服务器,在那里我们将与 git 同步并测试,如果一切正常 - 将只同步实时服务器。

希望这个场景能得到足够好的解释,但如果没有 - 请告诉我,我会进一步解释它。

提前致谢。

实时服务器继续使用原始代码,同时我们同步分布在多个服务器上的整个代码库。

最佳答案

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 存储库重置为首次提交(任何更改之前)
  • 将服务器代码添加到该 Git 存储库的专用分支中
  • 最后,将该分支 merge 到当前分支(这将保留所有最近的更改,但会使用专用分支中的服务器代码更新未更改的文件)

即:

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

实际上,来自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

那就更简单了:你不需要专用的分支:

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

关于git - 当前代码库的精细 git merge ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75066835/

相关文章:

git - 如何在 Git 中执行 "hg backout X"?

git describe 失败并显示 "fatal: No names found, cannot describe anything."

git - SmartGit:彩色复选框的含义

git 应用 --3way : don't abort if some hunks fail

git - 为什么 `go get` 尝试访问 http 而不是 https?

java - 在理解线程等待和通知方面需要帮助

c# - native C++ 等效于 C# 中的 ManualResetEvent

multithreading - 多线程意义上的机器指令假设

iOS:同步来自相机和运动数据的帧

android - 同步 Android 联系人与服务器 - 同步算法