简体   繁体   English

从实时服务器到中央存储库的“ git push --force”

[英]“git push --force” from live server to central repository

The answer to similar questions on SO seems to always be "merge/pull before pushing" or "don't get into the situation in the first place". SO上类似问题的答案似乎总是“在推入之前合并/拉动”或“一开始就不要陷入困境”。 Neither of those apply. 这些都不适用。

I've inherited maintenance of a website in which ongoing development has branched from maintenance of the old site. 我继承了网站的维护,从旧站点的维护中可以进行不断的开发。 However, I've discovered that legacy fixes weren't always made local->git->test->live. 但是,我发现旧版修复程序并不总是可以通过local-> git-> test-> live来实现。 Sometimes they were test->live, skipping git, and sometimes they were made directly to Live. 有时它们是test-> live,跳过git,有时它们是直接制作到Live。

Thus, the Live environment does not exactly match any git commit nor the test server nor my local environment. 因此,Live环境与任何git commit,测试服务器或本地环境都不完全匹配。 This is a problem. 这是个问题。

I created a new branch for how live currently is, but when I tried to push, git refused -- claiming changes had been made to the central repository, and "non-fast-forward updates were rejected". 我创建了一个新的分支来说明当前的状态,但是当我尝试推送时,git拒绝了—声称已对中央存储库进行了更改,并且“拒绝了非快速更新”。

I don't want to merge into the live server. 我不想合并到实时服务器中。 I think the unmerged changes are developmental (proper branch management wasn't always fastidiously followed), but even if there are fixes in the central that should be live, the live server is not the place to perform that merge. 认为未合并的更改是发展性的(并不总是严格遵循正确的分支管理),但是即使中央有一些应修复的补丁,实时服务器也不是执行合并的地方。

The answer seems to be a "git push --force" from live, and deal with merges and general git cleanup on the local. 答案似乎是现场直播的“ git push --force”,并在本地处理合并和常规git清理。

But I haven't used --force before, and from my searching for an answer, it seems to sometimes work differently than what people expect. 但是我以前没有使用过--force,从我寻找答案的过程中,它有时看起来和人们期望的有所不同。

So, I need a sanity-check. 因此,我需要进行健全性检查。 will: 将:

git checkout -b new_branch_name
git add -u
git add *
git commit -m "new branch to match how live is currently"
git push --force

push my new branch to the central repository exactly how it is on the server from which I'm running the commands, without affecting any other branches? 将我的新分支准确地推送到中央存储库,使其在我运行命令的服务器上的状态如何,而不会影响任何其他分支?

Contrarily, is there a better method to deal with getting the git repositories cleaned up, and a testing environment that matches live? 相反,是否有更好的方法来清理git存储库,并提供与实时匹配的测试环境?

Since this is the live server, I can't just-try-it-and-see-if-it-works. 由于这是实时服务器,因此我无法尝试并查看其是否有效。

Here's what I ended up doing: 我最终要做的是:

Just to avoid trying out how-I-think-git-works-but-I-haven't-actually-done-this-trick-previously on a live site, I created a NEW local repo from the current contents of the live server. 为了避免尝试如何在以前的实时站点上尝试我认为git的工作原理,但实际上并没有做到这一点,我从实时站点的当前内容中创建了一个新的本地存储库服务器。 From here, I can get fancy -- on my LOCAL drive -- with comparing and moving branches between repos, until I have this mess cleaned up. 从这里开始,我可以在本地驱动器上比较和移动存储库之间的分支,直到我清理完这些混乱为止。

Holding off on accepting my answer, in case someone with more knowledge posts a better one. 推迟接受我的答案,以防万一有更多知识的人发布更好的答案。

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

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