corazza
corazza

Reputation: 32354

In open source development, what is the difference between a patch and a git commit?

As far as I know, a patch is a file describing the differences between some files. It seem like a neat way to communicate changes in source code.

But a git commit does that, and so much more. Why send patch files over the email when you could do pull requests (with all the associated metainformation, git mechanisms, and automation)?

Essentially, why/when is one used over the other?

Upvotes: 2

Views: 120

Answers (2)

Guildenstern
Guildenstern

Reputation: 3801

Good question.

Let’s just assume that everyone is using Git. Then why ever use patches?

Some downsides of using commits:

  • You have to have a public repository somewhere in order to communicate with people
    • With git format-patch and git send-email you just need to have an email provider configured to send emails on your behalf
  • Email is a sort of lowest-common demoninatorb
    • This is debatable!—having to set up your email send-out for patch-based workflows (where the patches are embedded in the email) can be difficult, and even some very experienced developers (who have used this style of development for years or decades) thinks it’s antiquated
    • This means that tooling around patches needs to understand a well-established email format, compared to learning the APIs of all of the different Git forges
  • If you email patches to a public mailing list, you can gather the discussion around the patches on that email thread; you can discuss individual lines and hunks of code directly in the email
    • You could use Git forges together with email, but then you might have to constantly say things like “see commit on my GitHub”, “see commit on my GitLab”; everyone might have different forges that they just link to instead of discussing the code directly in the email

Agility

If you’re—skilled—I can’t comment personally on this point—, you can go from having a regular conversation to proposing changes immediately. For example: [1]

> So we should do such-and-such.

Makes sense to me.  How about this patch?

-- >8 --
Subject: [IA64] Put ia64 config files on the Uwe Kleine-König diet

arch/arm config files were slimmed down using a python script

Notes

  1. Taken from man git format-patch

Upvotes: 1

lisu
lisu

Reputation: 2263

One reason is that a patch is generic mechanism and is supported in every version control system (svn, cvs etc.). You can create patches of any changes in your file system, not even being under version control! Pull requests, on the other hand, are quite handy, but this is github (bitbucket etc.) specific mechanism, so it's less generic.

I think also some projects use patches because of historical reasons/habits.

Upvotes: 1

Related Questions