ge: export commits as patches
is there any 'export commit as patch' support in git-pasky? I didnt find any such command (maybe it got added meanwhile), so i'm using the 'ge' hack below.
e.g. i typically look at commits via 'git log', and then when i see something interesting, i look at the commit via the 'ge' script. E.g. "ge 834f6209b22af2941a8640f1e32b0f123c833061" done in the kernel tree will output a particular commit's header and the patch.
Ingo
#!/bin/bash
if [ $# != 1 ]; then
echo 'ge <commit-ID>'
exit -1
fi
TREE1=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^tree | cut -d' ' -f2) if [ "$TREE1" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi PARENT=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^parent | cut -d' ' -f2) if [ "$PARENT" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi TREE2=$(cat-file commit 2>/dev/null $PARENT | head -4 | grep ^tree | cut -d' ' -f2) if [ "$TREE2" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi
cat-file commit $1
echo
git diff -r $TREE2:$TREE1
Dear diary, on Tue, Apr 19, 2005 at 03:48:43PM CEST, I got a letter where Ingo Molnar <[email protected]> told me that...
Quoted 8 lines
is there any 'export commit as patch' support in git-pasky? I didnt find any such command (maybe it got added meanwhile), so i'm using the 'ge' hack below.
e.g. i typically look at commits via 'git log', and then when i see something interesting, i look at the commit via the 'ge' script. E.g. "ge
834f6209b22af2941a8640f1e32b0f123c833061" done in the kernel tree will output a particular commit's header and the patch.
Nice idea. I will add it, probably as 'git patch'.
Quoted 6 lines
TREE1=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^tree | cut -d' ' -f2) if [ "$TREE1" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi PARENT=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^parent | cut -d' ' -f2) if [ "$PARENT" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi TREE2=$(cat-file commit 2>/dev/null $PARENT | head -4 | grep ^tree | cut -d' ' -f2) if [ "$TREE2" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi
commit-id and parent-id tools might be useful. ;-)
Signature · 3 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
Quoted 13 lines · Petr Baudis
Dear diary, on Tue, Apr 19, 2005 at 03:48:43PM CEST, I got a letter where Ingo Molnar <[email protected]> told me that...
Quoted 8 lines
is there any 'export commit as patch' support in git-pasky? I didnt find any such command (maybe it got added meanwhile), so i'm using the 'ge' hack below.
e.g. i typically look at commits via 'git log', and then when i see something interesting, i look at the commit via the 'ge' script. E.g. "ge
834f6209b22af2941a8640f1e32b0f123c833061" done in the kernel tree will output a particular commit's header and the patch.Nice idea. I will add it, probably as 'git patch'.
Quoted 8 lines
Quoted 6 lines
TREE1=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^tree | cut -d' ' -f2) if [ "$TREE1" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi PARENT=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^parent | cut -d' ' -f2) if [ "$PARENT" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi TREE2=$(cat-file commit 2>/dev/null $PARENT | head -4 | grep ^tree | cut -d' ' -f2) if [ "$TREE2" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi
commit-id and parent-id tools might be useful. ;-)
find a cleaned up 'ge' script below.
and please fix gitXnormid.sh to simply echo nothing and return with a -1 exit value when a nonsensical ID is passed to it. Right now the output is quite ugly if you do 'ge blah'.
Ingo
#!/bin/bash
usage ()
{
echo 'usage: ge <commit-ID>'
exit -1
}
if [ $# != 1 ]; then
usage
fi
ME= $(commit-id $1); [ "$ME" = "" ] && usage PARENT=$(parent-id $ME); [ "$PARENT" = "" ] && usage TREE1= $(tree-id $ME); [ "$TREE1" = "" ] && usage
TREE2= $(tree-id $PARENT); [ "$TREE2" = "" ] && usage
cat-file commit $ME
echo
git diff -r $TREE2:$TREE1
Dear diary, on Tue, Apr 19, 2005 at 08:56:07PM CEST, I got a letter where Ingo Molnar <[email protected]> told me that...
Quoted 3 lines
and please fix
gitXnormid.shto simply echo nothing and return with a -1 exit value when a nonsensical ID is passed to it. Right now the output is quite ugly if you do 'ge blah'.
That's a feature; you can do || exit 1. Put its stderr to /dev/null if you want your own error reporting.
BTW, I still think my gitpatch.sh is nicer. ;-)
Signature · 3 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
Forget my earlier "aspatch" proposal, that's a lousy name.
How about "mkpatch"? Seems like a reasonable name for a command that makes a patch. GNU Arch uses that command name. CVS & Subversion basically do this as part of "diff" (which is another possibility).
--- David A. Wheeler
Quoted 6 lines · Petr Baudis
Dear diary, on Tue, Apr 19, 2005 at 03:48:43PM CEST, I got a letter where Ingo Molnar <[email protected]> told me that...
Quoted 4 lines
is there any 'export commit as patch' support in git-pasky? I didnt find any such command (maybe it got added meanwhile), so i'm using the 'ge' hack below.
Quoted 6 lines
Quoted 4 lines
e.g. i typically look at commits via 'git log', and then when i see something interesting, i look at the commit via the 'ge' script. E.g. "ge
834f6209b22af2941a8640f1e32b0f123c833061" done in the kernel tree will output a particular commit's header and the patch.Nice idea. I will add it, probably as 'git patch'.
Ah, thanks for doing this. 'git patch' works great (but you might want to mention in the 'help' that you can give the commit id for the patch, if you don't want to see the HEAD patch.)
thanks,
greg k-h
Quoted 4 lines · Petr Baudis
Dear diary, on Tue, Apr 19, 2005 at 03:48:43PM CEST, I got a letter where Ingo Molnar <[email protected]> told me that...
Quoted 8 lines
Quoted 3 lines
is there any 'export commit as patch' support in git-pasky?
Nice idea. I will add it, probably as 'git patch'.
Eek!
It's a nice idea, and it'd be great as a subcommand. But PLEASE don't name it "patch". I already know what "patch" does, "patch" ACCEPTS a patch... it doesn't create one ;-).
How about naming it "aspatch" or "asdiff" instead? Or something else (good names, anyone?).
<soapbox_to_choir>Good externally-viewed names are critical... good command names that are similar to what people "already know" can really help make the tool a joy to use.</soapbox_to_choir>
--- David A. Wheeler
Quoted 1 line · Ingo Molnar
TREE1=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^tree | cut -d' ' -f2)
--------------------------------------
And to make it easier on your eyes, you can always rewrite stuff like that (mentioned everywhere these days :)) like:
TREE1=$(cat-file commit 2>/dev/null $1 | awk '/^tree/ {print $2}'
------------------------
No, I'm definitely not trying to save some CPU cycles, CPU cycles are cheap, eyes are expensive! :)
Signature · 1 line
Zlatko