我如何修改一组Git补丁中的文件路径? [英] How can I modify the file path in a set of Git patches?

查看:133
本文介绍了我如何修改一组Git补丁中的文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 git svn 从SVN回购库中获取Git回购。在许多月前,SVN回购是从原始(上游)项目的源代码包创建的。原始项目的文件结构如下:

  / 
复制
自述文件
src /
...很多源文件...

但是,当SVN回购创建了README文件等,并且该应用程序是以 src / 作为根目录创建的,所以现在的repo如下所示:

  / 
...多个源文件

我最近将此SVN回购转换为Git回购。原始项目也在Git仓库中,我想开始跟踪上游的更改,以便我可以轻松地看到自定义的更改已完成(并将补丁提交回原始项目,如果适用的话)。我在上游回购中发现我们的SVN回购是从创建的,所以现在我想将我们的更改应用于该提交(在分支中)。我可以使用 git format-patch 轻松创建一组修补程序,并将它们应用到克隆的上游回购中,只是文件结构不同, t指向正确的文件了。有没有办法将修补程序从 git format-patch 应用到克隆回购中的 src / 目录中? (请注意,Git补丁还具有必要的信息,例如原始作者姓名,电子邮件和日期,我也希望应用这些信息,而不必亲手操作,即通过乱动 GIT_AUTHOR_EMAIL 等)

解决方案

在我看来,您应该可以使用 git filter-branch 更改之前克隆的SVN回购中的路径。然后,在所有文件路径被更新后,您现在可以使用 git format-patch 来创建应用于新创建的修补程序的修补程序,克隆从上游回购。



尝试:

git filter-branch - -tree-filter'mkdir src; git ls-tree --name-only $ GIT_COMMIT | xargs -I files mv files src'


I'm working on a Git repo that's been pulled from an SVN repo using git svn. Many moons ago, the SVN repo was created from a source tarball of the original (upstream) project. The original project had a file structure like the following:

/
  COPYING
  README
  src/
      ...many source files...

However, when the SVN repo was created, the README files, etc., were stripped out, and the app was created with src/ as the root, so the repo now just looks like:

/
  ...many source files

I recently converted this SVN repo into a Git repo. The original project is also in a Git repo, and I'd like to start tracking upstream changes so I can easily see what custom changes have been made (and submit patches back to the original project, if applicable). I've found the commit in the upstream repo that our SVN repo was created from, so now I'd like to apply our changes to that commit (in a branch). I can easily create a set of patches using git format-patch and apply them to the cloned upstream repo...except that the file structures are different, so the patches don't point to the correct files anymore. Is there a way to apply the patches from git format-patch to the src/ directory in the cloned repo? (Note that the Git patches also have the necessary info like the original author name, email, and date, which I'd also like to apply and not have to do by hand, i.e., by messing around with GIT_AUTHOR_EMAIL, etc.)

解决方案

Seems to me that you should be able to use git filter-branch to change the paths in the previously-cloned-from-SVN repo. Then, after all the file paths have been updated, you can now just use git format-patch to create patches that will apply to the newly-cloned-from-upstream repo.

Try:

git filter-branch --tree-filter 'mkdir src; git ls-tree --name-only $GIT_COMMIT | xargs -I files mv files src'

这篇关于我如何修改一组Git补丁中的文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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