how to add patch

Steve Howell showell30 at yahoo.com
Thu Oct 14 00:01:26 EDT 2010


On Oct 13, 12:36 pm, jimgardener <jimgarde... at gmail.com> wrote:
> hi
> I have some demo python  code hosted on a public host that uses
> subversion..and I want to modify one of the files using a patch file
> handed to me by another person..How do I do this?Generally I checkout
> the code and make the change and then commit again..I have never done
> through patch..Can somebody tell me how to do this?
> thanks

Obviously "man patch" is where you should start, but like many Unix
man pages, the man page for "patch" is surprisingly obtuse for such an
elegant and useful program.

(BTW we are slightly off-topic for Python, but I am sympathetic to
your basic problem.)

The "patch" program is pretty smart about doing the correct thing once
you grok its options, but if you are concerned about doing the wrong
thing, I recommend you simply play around with it with some toy
examples.

Hopefully the example below demonstrates the basic premise behind
"patch," which I think you already understand.  The bells and whistles
are mostly about "patch" being able to recognize that a diff applies
to a specific file.  Again, I would take a few minutes to experiment
with a couple small files and diffs that you generate yourself before
applying other people's patches.

I haven't used "patch" a ton myself, so I'm no expert, but it's
definitely a cool program, so it's worth learning.


  $ echo foo > foo
  $ cp foo foobetter
  $ echo better >> foobetter
  $ cat foo
  foo
  $ cat foobetter
  foo
  better
  $ diff foo foobetter
  1a2
  > better
  $ diff foo foobetter > make_foo_better
  $ patch foo make_foo_better
  patching file foo
  $ cat foo
  foo
  better



More information about the Python-list mailing list