Thread: Git, diffs, and patches

Git, diffs, and patches

From
Bruce Momjian
Date:
I learned a few things when working on the key management patch that I
want to share here in case it helps anyone:

*  git diff effectively creates a squashed diff of all commits/changes
*  git format-patch wants to retain each commit (no squash)
*  git format-patch has information about file name changes
   (add/rename/remove) that git diff does not

*  git apply and git am cannot process context diffs, only unified diffs
*  git apply only applies changes to the files and therefore cannot
   record file name changes in git, e.g., git add
*  git am applies and merges changes, including file name changes

*  to create a squashed format-patch, you have to create a new branch
   and merge --squash your changed branch into that, then use git
   format-patch
*  to create a squashed git format-patch on top of a lower branch
   you have to make a copy of the lower branch, merge --squash on the
   upper branch on top of that, and then use git format-patch comparing
   the lower branch to the upper one

Maybe everyone else knew these things, but I didn't.  I can provide more
details if desired.

-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EnterpriseDB                             https://enterprisedb.com

  The usefulness of a cup is in its emptiness, Bruce Lee




Re: Git, diffs, and patches

From
Bruce Momjian
Date:
On Fri, Jan 15, 2021 at 01:39:49PM -0500, Bruce Momjian wrote:
> I learned a few things when working on the key management patch that I
> want to share here in case it helps anyone:
...
> Maybe everyone else knew these things, but I didn't.  I can provide more
> details if desired.

One more learning is that git diff compares two source trees and outputs
a diff, while format-patch compares two trees with a common commit and
outputs a diff for each commit.  This is why format-patch can output
file name changes.

-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  The usefulness of a cup is in its emptiness, Bruce Lee