使用不同的目录结构在git存储库中移动补丁 [英] Moving patches in git repository with different directory structure

查看:69
本文介绍了使用不同的目录结构在git存储库中移动补丁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,标题有些冗长和混乱.我们有一个具有以下目录结构的git存储库(根代表存储库根;名称是虚构的):

I'm sorry for the somewhat verbose and confused title. We have a git repository with the following directory structure (the root represents the repository root; the names are fictional):

/
/dir1/
/dir2/
/dir2/subdir1/
/dir2/subdir2/

一个团队同事用/dir2/subdir1的副本创建了一个新的git存储库,即/dir2/subdir1成为了新存储库的根.我们在该新存储库中做了一些(〜15)次提交,然后我们决定要在旧存储库中复制新提交.

A team colleague created a new git repository with a copy of /dir2/subdir1, i.e. the /dir2/subdir1 became the root of the new repository. We did some (~15) commits in that new repository, then we decided that we would like to replicate the new commits in the old repository.

执行此操作的最佳方法是什么?

What is the best way to perform this action?

当然,我们可以从新存储库中创建一个补丁并将其作为旧提交中的单个提交应用,但是这样做会丢失历史的详细程度.

Of course we could create a patch from the new repository and apply it as single commit in the old one, but we would lose granularity of history by doing so.

在此期间,旧存储库中没有触及/dir2/subdir1的提交,因此绝对不应有冲突.

There have been no commits in the old repository in the meantime that touched /dir2/subdir1, so there should definitely be no conflicts.

推荐答案

解决方案是使用 git format-patch git am .在新的存储库中,我做了

The solution was to use git format-patch and git am. In the new repository I did a

git format-patch $revision

,其中$revision是新存储库中与旧存储库状态相对应的修订,即添加了/dir2/subdir1的修订.这样就创建了约15个文件,其中包含每个提交的补丁.

, where $revision is the revision in the new repository which corresponds to the status of the old repository, i.e. the revision where /dir2/subdir1 was added. This created around 15 files containing the patches of every single commit.

然后,我移至旧的存储库,并使用git am应用刚刚创建的补丁.我只需要指定必须应用这些补丁的目录:

Then I moved to the old repository and used git am to apply the patches just created. I just had to specify the directory where these patches had to be applied:

git am --directory dir2/subdir1 $patches

,其中$patches是在上一步中创建的文件.

, where $patches are the files created during the previous step.

现在,提交已从新存储库移到旧存储库,我很高兴!

Now the commits are moved from the new repo into the old one and I'm happy!

这篇关于使用不同的目录结构在git存储库中移动补丁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆