git am / format-patch:行结尾的控制格式 [英] git am/format-patch: control format of line endings

查看:160
本文介绍了git am / format-patch:行结尾的控制格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用

  git format-patch< revision_three_commits_ago> 

这会创建三个补丁文件,我从笔记本邮寄并读取我的台式计算机上的邮件





当我现在做的时候 git am --3way --ignore-space-change * .patch

补丁适用,但我不' t为提交获取相同的SHA1 ID。在补丁文件中搜索一下,我发现我的台式计算机上的修改过的行以 LF 结尾,而笔记本上的修改过的行(我创建补丁的地方)结束与 CR LF



所以,我的第一个想法是打电话给 git am without - ignore-space-change ,但是这给我一个错误(补丁不适用)。



我怎么能告诉 git format-patch git am 关于如何处理行结尾(msysgit 1.7.4)?



在我可以应用VIM之前,是否真的必须将VIM和文件格式从 UNIX 更改为 DOS 补丁?






编辑:甚至没有用VIM修改补丁文件有助于:我认为,设置ff = dos 和:%s / ^ M // g 会有所帮助,但它不会!



在我看来,应用修补程序应该导致恰好相同的内容,也是相同的提交散列,就像我从其他回购站获取的那样该补丁已创建。我在想这个问题吗?

解决方案

在玩过各种选项( core.autocrlf core.eol )我发现使用

  git am --keep-cr 

会这样做(但会导致关于结尾空格的警告)。



无需手动编辑补丁文件或其他脏东西。



但是,(当然)哈希是不同的,如 nikai 的答案...感谢nikai指向我的散列东西。



在我的笔记本电脑桌面场景中,我想从笔记本离线转移一些更改到台式计算机,但回购不应该分歧,也不应该在桌面上应用此修补程序时发生两次相同的提交,然后在笔记本计算机上执行 git pull desktop



为此,我做了以下操作:


  1. 在桌面上,使用 git am --keep-cr ...

  2. 应用上述补丁在笔记本上,使用 git pull desktop ,这会导致修补程序引入的每次提交都会发生两次(一次用于原始笔记本提交,一次用于修补并拉到桌面提交中)

  3. 现在(位于笔记本的 master 分支),发出 git rebase desktop / master 导致没有更改 - 修补程序已经应用消息,并且将原始笔记本提交踢出桌面提交


I created a patch from three commits using

git format-patch <revision_three_commits_ago>

This creates three patch files that I mailed from my notebook and read the mail on my desktop computer (both are Windows boxes).

When I do now

git am --3way --ignore-space-change *.patch

the patches apply, but I don't get the same SHA1 IDs for the commits. Searching a bit in the patched files, I found that the modified lines on my desktop computer end with LF, whereas the modified lines on the notebook (where I created the patch) end with CR LF.

So, my first thought was to call git am without --ignore-space-change, but this gives me an error (patch does not apply).

How could I tell git format-patch or git am about how to handle the line endings (msysgit 1.7.4)?

Do I really have to take VIM and change the file format from UNIX to DOS before I can apply the patches?


EDIT: Not even modifying the patch files with VIM helps: I thought, set ff=dos and a :%s/^M//g would help, but it doesn't!

In my opinion, applying a patch should result in exactly the same content and also the same commit hash like I pulled from the other repo where the patch was created. Am I thinking wrong about that?

解决方案

After playing around with various options (core.autocrlf, core.eol) I found that using

git am --keep-cr

does the trick (but causes a warning about trailing whitespaces).

No manual editing of the patch file or other dirt is neccessary.

But, (of course) the hash is different as described in nikai's answer... Thanks to nikai for pointing me to the hash stuff.

In my notebook-desktop-scenario, I wanted to transfer some changes offline from notebook to the desktop computer, but the repos should not diverge nor should the same commit occur twice when I applied the patch on the desktop and then do a git pull desktop from the notebook.

To achieve this, I did the following:

  1. On the desktop, apply the patch as described above using git am --keep-cr ...
  2. On the notebook, to a git pull desktop, which leads to the situation that each commit introduced by the patch occurs twice (once for the original notebook commit, once for the patched and pulled in desktop commit)
  3. Now (being on the master branch of the notebook), issuing a git rebase desktop/master leads to No changes -- Patch already applied message and kicks out the original notebook commits replaced by the desktop commits

这篇关于git am / format-patch:行结尾的控制格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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