如何在复制的存储库中合并远程和本地更改?

发布于 2024-11-07 10:28:16 字数 236 浏览 4 评论 0原文

我做了一些愚蠢的事情。我很着急,需要在笔记本电脑上保存代码,因此我使用 USB 驱动器将整个开发目录从桌面复制到笔记本电脑。

无论如何,开发目录包含一个 git 项目,自从我上次拉取以来,该项目已经有其他人推送了几次提交。问题是我对笔记本电脑上的代码进行了更改,更糟糕的是,我的台式电脑出现了驱动器故障。我的笔记本电脑甚至还没有 git,我无法将文件传输到我的 PC,然后与新代码合并。

安装了 git 后,我​​应该做什么?

I did something silly. I was in a hurry and needed my code on my laptop, so I copied my entire development directory from my desktop to my laptop, using a USB drive.

Anyways the development directory contained a git project which has had several commits pushed by others since I last pulled. Problem is I have made changes to the code on my laptop and to make things worse, my desktop PC has had a drive failure. My laptop does not even have git (yet), and I cannot transfer the files to my PC and then merge with the new code.

Once I have git installed, what should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酸甜透明夹心 2024-11-14 10:28:16

这根本不是一个巨大的灾难,因为 git 就是为了处理这种类型的事情而设计的。您只需记住,您实际上已经创建了另一个存储库。如果没有更多关于所做更改的详细信息,很难给出具体的建议,但通过明智地使用分支、挑选提交等,这应该是一个相对轻松的解决过程(尽管可能需要时间)。

根据您的 git 技能水平,例如,如果您相对较新,这似乎是一个难以克服的挑战。我建议您阅读如何执行挑选、分支和合并、如何推送到远程存储库(以及如何添加其他遥控器)等,因为您可能需要执行上述一些操作。您应该能够有效地将每个存储库视为一个离散的实体,并在它们之间进行推送和拉动以使它们同步(尽管,实际上您似乎只想从一个存储库中提取更改以形成您的主存储库并使其达到再次推送和拉取其他开发存储库之前的日期)。

通过快速谷歌搜索可以找到网络上一些很棒的资源。

如果没有更多信息,很难说可能涉及什么。

作为开始的建议,如果将两个存储库放在一台计算机上(将它们放在单独的目录中,您不想意外地将一个存储库复制到另一台计算机上),这可能是最简单的。然后在同一台计算机上,在“主”存储库中设置一个指向您想要从中提取更改的其他存储库的远程,然后最好执行“git fetch”以获取远程分支并开始手动合并过程(而不是执行拉取并自动合并所有内容,这可能不是您希望发生的事情)。完成此操作后,您就可以随意挑选和/或合并。

It's not really a huge disaster at all since git is designed to handle this type of thing. You just have to keep in mind that effectively you've created just another repository. It's hard to give concrete advice without more detail on what changes have been made, but through the judicious use of branching, cherry-picking commits etc, it should be a relatively painless process to resolve (although it may take time).

Depending on your skill level with git, for instance if you're relatively new, this could seem to be an insurmountable challenge. I recommend you do read up on how to perform cherry-picking, branching and merging, how to push to a remote repository (and also how to add additional remotes) etc, as you'll probably need to do a fair bit of the above. You should be able to effectively treat each repository as a discrete entity and push and pull between them to get them in sync (although, really it seems like you only want to be pulling changes from one to form your main repo and get it up to date before pushing and pulling to other dev repo's again).

There are some great resources on the web that can be found with some quick googling.

Without more information it's difficult to say what could be involved.

As a suggestion to get started, it's probably going to be easiest if you put the two repositories together on the one machine (put them in separate directories, you don't want to accidentally copy one over the other). Then on that same machine, in your "main" repository set up a remote pointing to the other repository you'd like to pull changes from, it's probably best to then perform a 'git fetch' to get the remote branches and head to begin the merging process manually (rather than performing a pull and having everything merge automatically, which might not be something you want to happen). Once you've done that, you can then cherry-pick and/or merge at your leisure.

故人的歌 2024-11-14 10:28:16

安装 git 后,您所需要做的就是引入新的更改,以便将它们与您的更改合并。就是这样。

Once you have git installed, all you need to do is to pull in the new changes so you can merge them with yours. That's it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文