Git:检索特定提交

发布于 2024-12-29 02:50:42 字数 62 浏览 1 评论 0原文

我需要将 git 存储库中的一组提交导出到存档。 我该怎么做? 使用 svn,我可以选择提交并导出到 zip。

I need to export to an archive a set of commits in a git repository.
How do I do this?
Using svn, I could choose commits and export to zip.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光病人 2025-01-05 02:50:42

要将存储库导出到某个提交:

git archive -o export.zip。将 替换为您要导出的提交编号。

要在两次提交之间创建补丁:

git diff COMMIT1 COMMIT2 >补丁.txt

To export the repository up to a certain commit:

git archive -o export.zip <COMMIT>. Replace <COMMIT> with the commit number you want to export.

To create a patch between two commits:

git diff COMMIT1 COMMIT2 > patch.txt

婴鹅 2025-01-05 02:50:42

Git 有一种为每次提交创建补丁的便捷方法。尽管这最初是作为一种格式化补丁以便可以通过电子邮件发送的方式,但它们是提取一组更改的便捷方法。

您需要的命令是 git format-patch ,而将这些格式化补丁应用回 git 的方式是使用 git am 命令。

例如,如果您有两个提交 C1 和 Cn,您希望将其导出为一组 git 补丁,则您只需要:

git format-patch -k C1..Cn

这将创建一组编号的补丁(在当前目录中)。每个补丁都是提交的差异,以及提交信息(标题、评论、作者、日期等)。

这不仅仅是两次提交之间的简单差异文件所能提供的。

Git has a handy way of creating a patch for each commit. Although this originally was meant as a way to format patches so that they can be sent through email, they are a handy way of extracting a set of changes.

The command you want is git format-patch and the way you apply these formatted patches back into git is with the git am command.

For example if you you have two commits C1 and Cn that you want to export as a set of git patches you only need:

git format-patch -k C1..Cn

This will create a set of numbered patches (in your current directory). Each patch will be a diff of the commit, as well as the commit information (Title, comment, author, date, etc).

This is a lot more than a simple diff file between two commits will provide you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文