如何将补丁应用于git,包括新文件和提交消息? [英] How to apply a patch to git including new files and commit message?

查看:103
本文介绍了如何将补丁应用于git,包括新文件和提交消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种通用的方法来转换由 git show git format-patch 生成的补丁文件。或甚至 diff 以最好的方式提交。



我期望以下功能:


  1. 应修改现有文件,并为新提交进行修改。

  2. 新文件应创建并启动。


  3. 如果补丁是使用 git format-patch ,commit消息应该被解析并用于新的提交。

  4. 如果补丁是使用 git show ,commit消息应该被解析并用于新的提交。

  5. 如果补丁不是由上述两个工具创建的,它仍然应该被处理。 / li>
  6. CLI应该能够接受多个补丁,从而创建多个提交。

我是最在我考虑创建一个新工具之前,我对现有解决方案感兴趣。

以前的研究:

最接近的工具是 git am 但失败了#5和#6,所以它对于这个目的没有用处。另一方面, git apply 不会自行创建提交,并且至少失败#2和#5。



在RPM specfile中以下列格式应用修补程序时:

  Patch0:abc.patch 
Patch1:xyz.patch

我正在使用以下sed命令构建脚本:

  sed -re' s /.*:*(。*)/ git apply \1 \& \& git add。 \&安培; \&安培; git commit -am \ 1 /'

这当然不会做#4和#5因为它总是使用补丁文件名作为提交消息,#7被解决。

解决方案

我知道你的问题是关于 diff git format-patch git show ,但所有那些将传输更改,而不是提交。



命令名为 git bundle 将转移提交,而不是作者,时间和一切。您可以阅读文档



基本上,您将创建一个包含至少新提交的包文件,然后发送该文件。接收器会将该文件克隆到一个存储库中,您可以合并,拉取或重新绑定等。

I am looking for a universal way to turn a patch file generated by git show, git format-patch or even diff in a commit the best way possible.

I would expect the following features:

  1. Existing files should be modified and the modifications staged for the new commit.
  2. New files should be created and staged for the new commit.
  3. File deletions should be staged for the new commit as well.
  4. If the patch was created using git format-patch, commit message should be parsed and used for the new commit.
  5. If the patch was created using git show, commit message should be parsed and used for the new commit.
  6. If the patch was not created by the two tools above, it should still be processed.
  7. The CLI should be able to accept multiple patches and thus create multiple commits.

I am mostly interested in existing solutions before I consider creating a new tool.

Previous research:

The closest tool is git am but fails #5 and #6 so it isn't useful for the purpose. On the other hand git apply doesn't create a commit on its own and fails at least #2 and #5. I'm not aware of tools that would be more successful than those two.

When applying patches from RPM specfile in the following format:

Patch0: abc.patch
Patch1: xyz.patch

I'm currently building a script using the following sed command:

sed -re 's/.*: *(.*)/git apply \1 \&\& git add . \&\& git commit -am \1/'

This of course doesn't do #4 and #5 as it always uses patch filename as the commit message and #7 is worked around.

解决方案

I know your'e asking about diff, git format-patch and git show but all of those will transfer changes, not commits.

There is command called git bundle that will transfer the commits instead, including author, time and everything. You can read up on the docs.

Basically you'll create a bundle file containing at least the new commits, then send that file around. The receiver will clone the file into a repository that you can merge, pull, rebase or anything from.

这篇关于如何将补丁应用于git,包括新文件和提交消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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