Alex Rivera | Logout

git am/format-patch: control format of line endings

Asked 2011-06-09T06:41:25.610
14

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?

Edit
Report

1 Answer

1

Short answer: git am --committer-date-is-author-date

Long story: I just discovered that I was in the same boat while trying to sneakernet commits between two repositories. After experimenting with git am's options, I noticed that the file IDs always matched, but that consecutive runs of git am were producing different commit IDs for the same options. It turns out that there are two timestamps -- the "author" timestamp you normally see, and a "committer" timestamp when the commit is created. The latter is set to the current time by default in git am. You need the --committer-date-is-author-date option to keep the dates in sync, which in turn will get your commit IDs in sync.

Because of this, I would say that git bundle is much more reliable if that is an option in your environment.

answered 2012-06-28T15:37:40.953

Your Answer