[Bradford] How to apply git patch
Michael Dorrington
michael.dorrington at member.fsf.org
Sat Jan 11 13:37:42 UTC 2020
On 10/01/2020 20:22, Devo Too via Bradford wrote:
> Hi Folks,
>
> I've been sent a git patch by the developer of dhcpcd. What on earth do
> I do with it? I can't even make out if the first line is part of the
> patch or a command and web searches are confusing rather then enlightening.
Basically, a patch file is a line-by-line difference between 2 versions
of files. This is also known as a "diff" since you can use the `diff`
command to produce them. Since Git is version control you can use Git
to produce a patch/diff between 2 versions; when it does that it uses
the fake directory 'a' for the "original" version and directory 'b' as
the "new" version. That's why the Git patch you have contains:
diff --git a/src/ipv6.c b/src/ipv6.c
If you have Git installed then you should be able to change to the
directory of the source code of dhcpd and run:
git apply --check location/of/your/dhcpd.patch
git apply location/of/your/dhcpd.patch
See `man git-apply`.
If you haven't got Git installed then you can use `patch`. In the dhcpd
source directory do:
patch -p1 --dry-run location/of/your/dhcpd.patch
patch -p1 location/of/your/dhcpd.patch
See `man patch`.
Answered more below inline ->
> Here are the first few lines. What follow those are definitely part of
> the patch itself.
>
> diff --git a/src/ipv6.c b/src/ipv6.c
> index c49300c1..92403912 100644
> --- a/src/ipv6.c
> +++ b/src/ipv6.c
> @@ -1554,7 +1554,9 @@ ipv6_newaddr(struct interface *ifp, const struct
> in6_addr *addr,
> tempaddr = false;
> #endif
>
> Is this correct and if not, what is correct:
It is correct.
> The first line is the command to run - or the first 4 lines?
The 1st line is the command that was/can be used to create the patch,
the 2nd line is Git stuff (see `man git-diff`) and 3rd & 4th are as
explained above.
> The rest is the patch, which I should save as a standard file with -
> what name? - in /root, before running the command?
The whole lot is the patch. You can save it with any name but recommend
using a name that helps you such as one that describes what the patch is
doing with `.patch` at the end like:
dhcpd-ipv6-widget-misfire-fix.patch
> Git is not installed but I understand the patch command should be able
> to handle it. Is that correct?
Correct, see above.
> Also, the line which contains "const struct" looks questionable to me.
> Is this correct code or a typo creating gobbledegook?
Not a typo. The "const" means it is a constant and "struct" is a structure.
You will need to compile/build the source code to get a program with
patch in it.
> The responder with the sensible, working answer will be entitled to a
> drink from me on Tuesday evening after the LUG.
Can I get a voucher instead?
M.
P.S.
More on patch: https://en.wikipedia.org/wiki/Patch_(Unix)
--
FSF member #9429
http://www.fsf.org/register_form?referrer=9429
http://www.fsf.org/about
"The Free Software Foundation (FSF) is a nonprofit with a worldwide
mission to promote computer user freedom and to defend the rights of all
free software users."
More information about the Bradford
mailing list