简体   繁体   English

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

[英]How can I merge remote and local changes in my copied repository?

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. 我匆忙,需要在我的笔记本电脑上使用我的代码,所以我使用USB驱动器将我的整个开发目录从桌面复制到我的笔记本电脑。

Anyways the development directory contained a git project which has had several commits pushed by others since I last pulled. 无论如何,开发目录包含一个git项目,自从我上次提取以来,已经有其他人提交过多次提交。 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. 我的笔记本电脑甚至没有git(还),我无法将文件传输到我的电脑,然后与新代码合并。

Once I have git installed, what should I do? 一旦安装了git,我该怎么办?

It's not really a huge disaster at all since git is designed to handle this type of thing. 这根本不是一场巨大的灾难,因为git旨在处理这类事情。 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. 根据你的git技能水平,例如,如果你是相对较新的,这似乎是一个不可逾越的挑战。 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). 您应该能够有效地将每个存储库视为一个独立的实体,并在它们之间进行推拉以使它们保持同步(尽管,实际上您似乎只想从一个存储库中提取更改以形成您的主存储库并将其转换为再次推送和拉动到其他dev repo之前的日期)。

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). 然后在同一台机器上,在你的“主”存储库中设置一个指向你想要从中提取变化的另一个存储库的遥控器,然后最好执行'git fetch'来获取远程分支并开始手动合并过程(而不是执行拉动并使所有内容自动合并,这可能不是您想要发生的事情)。 Once you've done that, you can then cherry-pick and/or merge at your leisure. 完成后,您可以随意挑选和/或合并。

Once you have git installed, all you need to do is to pull in the new changes so you can merge them with yours. 一旦安装了git,您需要做的就是引入新的更改,以便将它们与您的更改合并。 That's it. 而已。

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

相关问题 如何在bit-bucket上将我的本地存储库与远程存储库合并? - How to merge my local repository with remote repository on bit-bucket? 合并从远程github存储库到本地存储库的更改 - Merge changes from remote github repository to your local repository Git和TortoiseSVN,我如何撤消本地存储库中的更改,而无需再次克隆远程仓库 - Git and TortoiseSVN, how do i undo my changes in local repository without cloning the remote repo again 如何将特定文件夹从来源(远程存储库)拉入本地主存储库 - How can i pull a specific folder from origin (Remote repository) into my local master repository git-svn如何合并从本地git repo到其他远程svn分支的更改? - git-svn How can I merge changes from a local git repo to a different remote svn branch? 将本地存储库合并到远程存储库 - merge local repository to remote repository 如何将本地分支与服务器上的远程分支合并? - How can I merge my local branch with my remote branch on my server? 我可以使用同一存储库的远程.git替换本地.git吗? - Can I replace my local .git with a remote .git for the same repository? 为什么我不能将此远程GitHub存储库添加为本地GIT存储库? - Why I can't add this remote GitHub repository to my local GIT repository as remote? 如何合并本地和远程分支之间的更改? - How to merge changes between local and remote branch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM