git newbie error - 如何恢复

时间:2022-08-04 00:01:11

Possibly related to Git - pulling changes from clone back onto the master

可能与Git有关 - 将克隆的更改拉回到主服务器上

I was working on an ASP.NET project when I discovered I needed to make an "experimental" set of changes which may or may not have been required in the production version.

当我发现我需要制作一组“实验性”变更时,我正在研究一个ASP.NET项目,这些变更可能在生产版本中可能需要也可能不需要。

The obvious thing to do was to create a branch.

显而易见的事情是创建一个分支。

However as I was familiar with darcs and svn but not git, I assumed that a clone was the "normal" way to create a branch (I now know that git branch would have been more appropriate.)

然而,由于我熟悉darcs和svn但不熟悉git,我认为克隆是创建分支的“正常”方式(我现在知道git分支会更合适。)

I continued to work on the experimental change in the clone and, at the same time, other changes in the original repository.

我继续研究克隆中的实验性更改,同时还对原始存储库中的其他更改进行了研究。

Since then I have discovered that the experimental changes are desirable in the production version and would like to merge the two change sets.

从那时起,我发现实验中的变化在生产版本中是可取的,并且想要合并两个变更集。

If I had originally done a branch instead of a clone, this would be trivial. I'm sure it's not too hard to merge between separate repositories, but having looked through the docs I don't think it can be done with a single command (a simple pull does not work.)

如果我最初做了一个分支而不是一个克隆,这将是微不足道的。我确定在单独的存储库之间进行合并并不太难,但是通过查看文档我不认为可以使用单个命令完成(简单的拉动不起作用。)

I haven't (yet) explicitly configured one repository as a "remote" of the other, but I am guessing this will be part of the solution.

我还没有(还)明确地将一个存储库配置为另一个存储库的“远程”,但我猜这将是解决方案的一部分。

The upstream repository at the time did not use any VCS - it was just a directory full of zips with version numbers appended to the file names.

当时的上游存储库没有使用任何VCS - 它只是一个充满拉链的目录,版本号附加到文件名。

So I would like to know:

所以我想知道:

  • What's the easiest way to merge the change sets across repositories? (I don't expect any major conflicts.)
  • 在存储库中合并更改集的最简单方法是什么? (我不指望有任何重大冲突。)

  • Just how harmful is it to clone instead of branching? Have I lost any information by doing this, e.g. shared history, common dependencies?
  • 克隆而不是分支有多害?这样做是否丢失了任何信息,例如共享历史,共同依赖?

3 个解决方案

#1


In your original "un-branched" git repository, run these commands:

在您原来的“未分支”git存储库中,运行以下命令:

git remote add name_it_anything /path/to/the/other/git/repository
git fetch name_it_anything
git merge name_it_anything/master

That will merge inn all the changes in nname_it_anything. If you don't want all of them, but just a selection of the commits, you can git log name_it_anything/master to see the list of commits and then git cherry-pick [SHA] for each of the commits you want to merge.

这将合并nname_it_anything中的所有更改。如果你不想要所有这些,只需要选择一些提交,你可以git log name_it_anything / master来查看提交列表,然后为你要合并的每个提交git cherry-pick [SHA]。

#2


Regarding the second part of your question:

关于你问题的第二部分:

Just how harmful is it to clone instead of branching? Have I lost any information by doing this, e.g. shared history, common dependencies?

克隆而不是分支有多害?这样做是否丢失了任何信息,例如共享历史,共同依赖?

Git is a distributed version control system. The whole point of a DVCS is to be able to merge changes back and forth between different repositories.

Git是一个分布式版本控制系统。 DVCS的重点是能够在不同的存储库之间来回合并更改。

#3


I think you can git-format-patch in one repository, and then apply in another. This way all important information is preserved.

我认为你可以在一个存储库中进行git-format-patch,然后在另一个存储库中应用。这样就可以保留所有重要信息。

#1


In your original "un-branched" git repository, run these commands:

在您原来的“未分支”git存储库中,运行以下命令:

git remote add name_it_anything /path/to/the/other/git/repository
git fetch name_it_anything
git merge name_it_anything/master

That will merge inn all the changes in nname_it_anything. If you don't want all of them, but just a selection of the commits, you can git log name_it_anything/master to see the list of commits and then git cherry-pick [SHA] for each of the commits you want to merge.

这将合并nname_it_anything中的所有更改。如果你不想要所有这些,只需要选择一些提交,你可以git log name_it_anything / master来查看提交列表,然后为你要合并的每个提交git cherry-pick [SHA]。

#2


Regarding the second part of your question:

关于你问题的第二部分:

Just how harmful is it to clone instead of branching? Have I lost any information by doing this, e.g. shared history, common dependencies?

克隆而不是分支有多害?这样做是否丢失了任何信息,例如共享历史,共同依赖?

Git is a distributed version control system. The whole point of a DVCS is to be able to merge changes back and forth between different repositories.

Git是一个分布式版本控制系统。 DVCS的重点是能够在不同的存储库之间来回合并更改。

#3


I think you can git-format-patch in one repository, and then apply in another. This way all important information is preserved.

我认为你可以在一个存储库中进行git-format-patch,然后在另一个存储库中应用。这样就可以保留所有重要信息。