{"thread":{"id":"1019","subject":"Re: git Tutorial?","startedAt":"2005-06-24T16:37:06Z","lastAt":"2005-06-25T01:27:37Z","messageCount":2,"participants":["Linus Torvalds","Patrick Mochel"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"5229","messageId":"Pine.LNX.4.58.0506240910040.11175@ppc970.osdl.org","threadId":"1019","inReplyTo":"Pine.LNX.4.50.0506240842090.24799-100000@monsoon.he.net","subject":"Re: git Tutorial?","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-06-24T16:37:06Z","receivedAt":"2005-06-24T16:37:06Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\n[ git-list cc'd, since these example things might be useful to others ]\n\nOn Fri, 24 Jun 2005, Patrick Mochel wrote:\n> \n> I've been able to make my away around a bit so far. And, as long as\n> everything is cached in memory, it's pretty damn fast.\n\nIndeed. It can be slow if things aren't in cache, but even then it's \nusually not really slower than something like CVS would be.\n\n> The handy things I've noticed missing are the equivalents of\n> \n> - bk changes -u<user> (Great for tracking down a change one did)\n\nYou can script it (and if you do so nicely, feel free to send me a \npatch). Here's the magic long-hand version that does something fairly \nclose to it:\n\n\tgit-rev-list --header HEAD |\n\t\tgrep -z author.*torvalds |\n\t\ttr '\\0\\n' '\\n:' |\n\t\tcut -d: -f1 |\n\t\tgit-diff-tree --pretty --stdin -p |\n\t\tless -S\n\n(That's really hacky, because \"cut\" and other standard unix tools don't \nlike using '\\0' as a record separator, but hey, whatever works..)\n\nThe above gives the result in \"git-whatchanged\" format, ie you get the\npatch too. If you don't want to see the patch, give the \"-s\" flag to\ngit-diff-tree instead of the \"-p\" flag, but if you script it, I'd suggest\nallowing the user to give that as an option to the script.\n\n> - bk undo (Good for fixing a quick screw up)\n\nSame deal. No nice script, but it's easy to do:\n\n - find the top-of-tree you want to go back to. If you know this is the \n   parent of the current HEAD, you can use the git-rev-parse helper:\n\n\ttarget=$(git-rev-parse HEAD^)\n\n   to find that.\n\n - do a \"fast-forward\" from the current HEAD to the head you want to go \n   to. Never mind that it's a \"fast-backward\" in this case, that's \n   symmetrical:\n\n\tgit-read-tree -m -u HEAD $target &&\n\t\t(echo $target > .git/HEAD)\n\n   This magic line just says \"merge (-m) while keeping the working \n   directory up-to-date with the changes (-u) from my current position \n   (HEAD) to my new position ($target), and if that worked, write the new \n   position into the HEAD file\"\n\n - If you then want to get _rid_ of the old HEAD stuff (ie you know you \n   don't want to go back to it) you can then follow up with a \"git prune\", \n   which will prune away all the unreachable objects. Be careful, though, \n   that really _will_ throw it all away, and it's gone, gone, gone. Before \n   you did \"git prune\", you could still get your old data back by just \n   looking for unconnected commits (git-fsck-cache and git-cat-file will\n   help you) and doing the above in reverse.\n\nAnd that was it. You can make it even nicer when scripting by using \nsomething like this\n\n\t#!/bin/sh\n\n\t# get the thing to undo to (default the first parent of the\n\t# last commit, regardless of whether it was a merge or a\n\t# regular commit\n\t# \n\tdefault_target=$(git-rev-parse HEAD^)\n\ttarget=$(git-rev-parse --default $default_target --revs-only \"$@\")\n\n\t# Check that it's a valid commit\n\tgit-cat-file commit \"$target\" > /dev/null || exit 1\n\n\t# Do it\n\tgit-read-tree -m -u HEAD $target &&\n\t\t(echo $target > .git/HEAD)\n\nand then you can add some fancy flags or whatever.\n\n> - bk export -tpatch -r<rev>\n\nThis one is trivial.\n\n\tgit-diff-tree --pretty $rev\n\ndoes exactly that: it shows a single revision, with a pretty changelog.\n\nAnd if you want to get diffs or ranges, use\n\n\tgit diff rev1..rev2\n\nor similar.\n\n\t\tLinus\n"},{"id":"5247","messageId":"Pine.LNX.4.50.0506241807260.29122-100000@monsoon.he.net","threadId":"1019","inReplyTo":"Pine.LNX.4.58.0506240910040.11175@ppc970.osdl.org","subject":"Re: git Tutorial?","fromName":"Patrick Mochel","fromEmail":"mochel@digitalimplant.org","sentAt":"2005-06-25T01:27:37Z","receivedAt":"2005-06-25T01:27:37Z","isPatch":false,"sender":{"key":"mochel@digitalimplant.org","avatar":null},"body":"\nOn Fri, 24 Jun 2005, Linus Torvalds wrote:\n\n>\n>\n> [ git-list cc'd, since these example things might be useful to others ]\n>\n> On Fri, 24 Jun 2005, Patrick Mochel wrote:\n\n> > The handy things I've noticed missing are the equivalents of\n> >\n> > - bk changes -u<user> (Great for tracking down a change one did)\n>\n> You can script it (and if you do so nicely, feel free to send me a\n> patch). Here's the magic long-hand version that does something fairly\n> close to it:\n>\n> \tgit-rev-list --header HEAD |\n> \t\tgrep -z author.*torvalds |\n> \t\ttr '\\0\\n' '\\n:' |\n> \t\tcut -d: -f1 |\n> \t\tgit-diff-tree --pretty --stdin -p |\n> \t\tless -S\n>\n> (That's really hacky, because \"cut\" and other standard unix tools don't\n> like using '\\0' as a record separator, but hey, whatever works..)\n>\n> The above gives the result in \"git-whatchanged\" format, ie you get the\n> patch too. If you don't want to see the patch, give the \"-s\" flag to\n> git-diff-tree instead of the \"-p\" flag, but if you script it, I'd suggest\n> allowing the user to give that as an option to the script.\n\nOk, it ain't exactly pretty, but it works.\n\nBelow is a patch to git-whatchanged that adds some optional parameters to\nit that allow users to filter the changesets returned by git-rev-list.\n\n\t-a\tSpecify the author's name.\n\t\tThis can be any part of the \"author\" line: the first name,\n\t\tthe last name, both, the login name, the domain name, or\n\t\tthe entire email address.\n\n\t\tFor example:\n\n\t\tgit-whatchanged -a \"Linus\"\n\t\tgit-whatchanged -a \"Linus Torvalds\"\n\t\tgit-whatchanged -a \"torvalds\"\n\t\tgit-whatchanged -a \"torvalds@ppc970.osdl.org\"\n\t\tgit-whatchanged -a \"@osdl.org\"\n\n\t-c\tSpecify the committer's name\n\t\tLike the above, this can be any part of the \"committer\"\n\t\tline. For example:\n\n\t\tgit-whatchanged -c \"Greg\"\n\t\tgit-whatchanged -c \"suse.de\"\n\t\tgit-whatchanged -c \"gregkh@suse.de\"\n\n\n\tAnd for good measure:\n\n\t-s\tSpecify a person that signed off on a patch.\n\n\t\tgit-whatchanged -s \"Linus Torvalds\"\n\t\tgit-whatchanged -s \"mochel@digitalimplant.org\"\n\n\t\tIt doesn't support multiple \"Signed-off-by\" entries.\n\n\tThey can also be used together:\n\n\tgit-whatchanged -a mochel@digitalimplant.org -c gregkh@suse.de\n\tgit-whatchanged -a Dunlap -s Torvalds\n\nBy default, it still just prints the changeset comments. Passing '-p' will\nprint the patches.\n\nPlease note that my script-fu isn't exactly good, so the patch is probably\ndone in the worst possible way. Please feel free to rewrite it or simply\njust toss it.\n\nThanks,\n\n\n\tPat\n\n\ndiff --git a/git-whatchanged b/git-whatchanged\n--- a/git-whatchanged\n+++ b/git-whatchanged\n@@ -1,4 +1,44 @@\n #!/bin/sh\n-git-rev-list $(git-rev-parse --default HEAD --revs-only \"$@\") |\n-\tgit-diff-tree --stdin --pretty -r $(git-rev-parse --no-revs \"$@\") |\n+\n+Author=\"\"\n+Committer=\"\"\n+SignedOffBy=\"\"\n+Args=\"\"\n+\n+while [ $# -gt 0 ] ; do\n+\n+\techo $1\n+case $1 in\n+\t-a)\n+\t\tshift\n+\t\tAuthor=\"$1\"\n+\t\t;;\n+\t-c)\n+\t\tshift\n+\t\tCommitter=\"$1\"\n+\t\t;;\n+\t-s)\n+\t\tshift\n+\t\tSignedOffBy=\"$1\"\n+\t\t;;\n+\t*)\n+\t\tArgs=\"$Args $1\"\n+\t\t;;\n+\n+esac\n+\tshift\n+done\n+\n+filter_cset() {\n+\tegrep -z \"author[[:print:]]+$Author\" |\n+\tegrep -z \"committer[[:print:]]+$Committer\" |\n+\tegrep -z \"Signed-off-by:[[:print:]]+$SignedOffBy\"\n+}\n+\n+\n+git-rev-list --header $(git-rev-parse --default HEAD --revs-only \"$Args\") |\n+\tfilter_cset |\n+\ttr '\\0\\n' '\\n:' | cut -d: -f1 |\n+\tgit-diff-tree --stdin --pretty $(git-rev-parse --no-revs \"$Args\") |\n \tLESS=\"$LESS -S\" ${PAGER:-less}\n+\n"}]}