Git patch command

A reminder on how use the git patch command.

Posted: Mon 18 May, 2015, 10:59
Was sent a Git patch file for the first time today, from another dev who needs me to finish something off for them. I took a quick look into the file and the file is actually just all the individual file diffs within one ASCII file, nothing more. This kind of makes sense I guess - as most things do in Git - as normal diff output is not just human-readable, but contains enough to reapply the changes programmatically.

    --- a/WebInterface/customer/xslt/Query.xslt
        +++ b/WebInterface/customer/xslt/Query.xslt
        @@ -43,10 +43,22 @@
         			<xsl:element name="PersonDescriptions">
        -				<xsl:attribute name="count"><xsl:value-of select="count(DATASET[@entity = 'PERSONDESC']/ROW)"/></xsl:attribute>			
        -				<xsl:for-each select="DATASET[@entity = 'PERSONDESC']/ROW">
        -					<xsl:apply-templates select="." />
        -				</xsl:for-each>			
        +				<xsl:attribute name="count">1</xsl:attribute>
        +				<PersonDescription>
        +					<xsl:for-each select="DATASET[@entity = 'PERSONDESC']/ROW">
        +						<xsl:sort select="PersonDesc__CretimeTZV2C" order="descending" />
        +						<xsl:if test="position()=1">
        +							<xsl:apply-templates select="." />''

To try out the patch without actually applying it then run:

git apply --check /tmp/fix.patch

Which will return nothing if all is fine. Then to run the patch just do:

git apply /tmp/fix.patch

Warnings will be summarised and then changes applied from the patch can be viewed with simply git diff.