简体   繁体   English

如何防止 git 格式补丁截断文件名

[英]How to prevent git format-patch from truncating filenames

I use git format-patch to share a list of patches for code review with my team members.我使用 git 格式补丁与我的团队成员共享补丁列表以供代码审查。 The problem is I sometimes have quite a long commit message, and git format-patch truncates them when generating the files.问题是我有时会收到很长的提交消息,并且 git 格式补丁会在生成文件时截断它们。

For example, I'd like to have a patch named 001-My-complete-message-bla-bla-bla.diff, but I get something like 001-My-comp.diff which doesn't help much understanding what there is inside.例如,我想要一个名为 001-My-complete-message-bla-bla-bla.diff 的补丁,但我得到了 001-My-comp.diff 之类的东西,这对理解其中的内容没有多大帮助里面。

I've searched everywhere about it for hours but I can't find any answer.我已经到处搜索了几个小时,但找不到任何答案。 It would be curious that no option exist to manage this.奇怪的是,不存在管理这个问题的选项。

Thanks in advance.提前致谢。

9 years later, there seems to be a solution (compared to my old answer ) with Git 2.30 (Q1 2021). 9 年后,Git 2.30(2021 年第一季度)似乎有一个解决方案(与我的旧答案相比)。

The maximum length of output filenames " git format-patch " ( man ) creates has become configurable (used to be capped at 64). output 文件名“ git format-patchman创建的最大长度已变为可配置(过去上限为 64)。

See commit 3baf58b (06 Nov 2020) by Junio C Hamano ( gitster ) .请参阅Junio C Hamano ( gitster ) 的提交 3baf58b(2020 年 11 月 6 日)
(Merged by Junio C Hamano -- gitster -- in commit 473c622 , 21 Nov 2020) (由Junio C Hamano -- gitster --提交 473c622中合并,2020 年 11 月 21 日)

format-patch : make output filename configurable format-patch :使 output 文件名可配置

For the past 15 years, we've used the hardcoded 64 as the length limit of the filename of the output from the " git format-patch " ( man ) command.在过去的 15 年中,我们使用硬编码的 64 作为“ git format-patchman命令中 output 文件名的长度限制。

Since the value is shorter than the 80-column terminal, it could grow without line wrapping a bit.由于该值比 80 列终端短,因此它可以在没有换行的情况下增长。
At the same time, since the value is longer than half of the 80-column terminal, we could fit two or more of them in " ls " output on such a terminal if we allowed to lower it.同时,由于该值超过了 80 列终端的一半,如果允许降低,我们可以在这样的终端上的“ ls ”output 中放入两个或更多。

Introduce a new command line option --filename-max-length=<n> and a new configuration variable format.filenameMaxLength to override the hardcoded default.引入一个新的命令行选项--filename-max-length=<n>和一个新的配置变量format.filenameMaxLength来覆盖硬编码的默认值。

While we are at it, remove a check that the name of output directory does not exceed PATH_MAX---this check is pointless in that by the time control reaches the function, the caller would already have done an equivalent of " mkdir -p ", so if the system does not like an overly long directory name, the control wouldn't have reached here, and otherwise, we know that the system allowed the output directory to exist.当我们这样做时,删除 output 目录的名称不超过PATH_MAX---this检查是没有意义的,因为当控制到达 function 时,调用者已经完成了相当于“ mkdir -p ”的操作,所以如果系统不喜欢过长的目录名,控件就不会到达这里,否则,我们知道系统允许output目录存在。
In the worst case, we will get an error when we try to open the output file and handle the error correctly anyway.在最坏的情况下,当我们尝试打开 output 文件并正确处理错误时,我们将得到一个错误。

git config now includes in its man page : git config现在包含在其手册页中:

format.filenameMaxLength

The maximum length of the output filenames generated by the format-patch command; format-patch命令生成的 output 文件名的最大长度; defaults to 64.默认为 64。
Can be overridden by the --filename-max-length=<n> command line option.可以被--filename-max-length=<n>命令行选项覆盖。

git format-patch now includes in its man page : git format-patch现在包含在其手册页中:

--filename-max-length=<n>

Instead of the standard 64 bytes, chomp the generated output filenames at around ' <n> ' bytes (too short a value will be silently raised to a reasonable length).代替标准的 64 字节,将生成的 output 文件名压缩到大约 ' <n> ' 字节(太短的值将被默默地提升到合理的长度)。
Defaults to the value of the format.filenameMaxLength configuration variable, or 64 if unconfigured.默认为format.filenameMaxLength配置变量的值,如果未配置,则为 64。

If there is no solution on the format-patch front, one possible workaround would be to make an incremental bundle , which:如果在格式补丁方面没有解决方案,一种可能的解决方法是制作增量 bundle ,它:

  • would result in only one file (instead of many for the patches )只会产生一个文件(而不是补丁的多个文件)
  • would support a kind of git log with git bundle verify : it will list the commits included in that bundle, with their (complete!) log message将支持一种git loggit bundle verify :它将列出该捆绑中包含的提交,以及他们的(完整!)日志消息

Abizern suggests a temporary branch for applying and examining those patches before merging back to their own branch. Abizern建议在合并回自己的分支之前使用一个临时分支来应用和检查这些补丁。
That is a possibility, but still, log messages are nice;)这是一种可能性,但日志消息仍然很好;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM