git 新手错误 - 如何恢复
当我发现我需要进行一组“实验性”更改时,我正在开发一个 ASP.NET 项目,这些更改在生产版本中可能需要也可能不需要。
显而易见的事情就是创建一个分支。
然而,由于我熟悉 darcs 和 svn 但不熟悉 git,我认为克隆是创建分支的“正常”方式(我现在知道 gitbranch
会更合适。
)继续对克隆进行实验性更改,同时对原始存储库进行其他更改。
从那时起,我发现实验性更改在生产版本中是可取的,并且希望合并两个更改集。
如果我最初做了一个分支而不是克隆,这将是微不足道的。 我确信在不同的存储库之间合并并不是太难,但是在查看了文档之后,我认为它不能用单个命令来完成(简单的pull
不起作用。
)还没有明确地将一个存储库配置为另一个存储库的“远程”,但我猜测这将是解决方案的一部分。
当时的上游存储库没有使用任何 VCS - 它只是一个充满 zip 的目录,版本号附加到文件名。
所以我想知道:
- 跨存储库合并更改集的最简单方法是什么? (我预计不会出现任何重大冲突。)
- 克隆而不是分支到底有多大危害? 我这样做是否丢失了任何信息,例如共享历史记录、共同依赖项?
Possibly related to Git - pulling changes from clone back onto the master
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.
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.)
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在原始的“未分支”git 存储库中,运行以下命令:
这将合并 n
name_it_anything
中的所有更改。 如果您不需要所有这些,而只是选择提交,您可以 git log name_it_anything/master 来查看提交列表,然后 gitcherry-pick [SHA] 对于您要合并的每个提交。In your original "un-branched" git repository, run these commands:
That will merge inn all the changes in n
name_it_anything
. If you don't want all of them, but just a selection of the commits, you cangit log name_it_anything/master
to see the list of commits and thengit cherry-pick [SHA]
for each of the commits you want to merge.关于你问题的第二部分:
Git 是一个分布式版本控制系统。 DVCS 的重点是能够在不同存储库之间来回合并更改。
Regarding the second part of your question:
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-format-patch ,然后在另一个存储库中应用。 这样所有重要信息都会被保留。
I think you can git-format-patch in one repository, and then apply in another. This way all important information is preserved.