All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: git Tutorial?
       [not found]   ` <Pine.LNX.4.50.0506240842090.24799-100000@monsoon.he.net>
@ 2005-06-24 16:37     ` Linus Torvalds
  2005-06-25  1:27       ` Patrick Mochel
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Torvalds @ 2005-06-24 16:37 UTC (permalink / raw)
  To: Patrick Mochel; +Cc: Git Mailing List



[ git-list cc'd, since these example things might be useful to others ]

On Fri, 24 Jun 2005, Patrick Mochel wrote:
> 
> I've been able to make my away around a bit so far. And, as long as
> everything is cached in memory, it's pretty damn fast.

Indeed. It can be slow if things aren't in cache, but even then it's 
usually not really slower than something like CVS would be.

> The handy things I've noticed missing are the equivalents of
> 
> - bk changes -u<user> (Great for tracking down a change one did)

You can script it (and if you do so nicely, feel free to send me a 
patch). Here's the magic long-hand version that does something fairly 
close to it:

	git-rev-list --header HEAD |
		grep -z author.*torvalds |
		tr '\0\n' '\n:' |
		cut -d: -f1 |
		git-diff-tree --pretty --stdin -p |
		less -S

(That's really hacky, because "cut" and other standard unix tools don't 
like using '\0' as a record separator, but hey, whatever works..)

The above gives the result in "git-whatchanged" format, ie you get the
patch too. If you don't want to see the patch, give the "-s" flag to
git-diff-tree instead of the "-p" flag, but if you script it, I'd suggest
allowing the user to give that as an option to the script.

> - bk undo (Good for fixing a quick screw up)

Same deal. No nice script, but it's easy to do:

 - find the top-of-tree you want to go back to. If you know this is the 
   parent of the current HEAD, you can use the git-rev-parse helper:

	target=$(git-rev-parse HEAD^)

   to find that.

 - do a "fast-forward" from the current HEAD to the head you want to go 
   to. Never mind that it's a "fast-backward" in this case, that's 
   symmetrical:

	git-read-tree -m -u HEAD $target &&
		(echo $target > .git/HEAD)

   This magic line just says "merge (-m) while keeping the working 
   directory up-to-date with the changes (-u) from my current position 
   (HEAD) to my new position ($target), and if that worked, write the new 
   position into the HEAD file"

 - If you then want to get _rid_ of the old HEAD stuff (ie you know you 
   don't want to go back to it) you can then follow up with a "git prune", 
   which will prune away all the unreachable objects. Be careful, though, 
   that really _will_ throw it all away, and it's gone, gone, gone. Before 
   you did "git prune", you could still get your old data back by just 
   looking for unconnected commits (git-fsck-cache and git-cat-file will
   help you) and doing the above in reverse.

And that was it. You can make it even nicer when scripting by using 
something like this

	#!/bin/sh

	# get the thing to undo to (default the first parent of the
	# last commit, regardless of whether it was a merge or a
	# regular commit
	# 
	default_target=$(git-rev-parse HEAD^)
	target=$(git-rev-parse --default $default_target --revs-only "$@")

	# Check that it's a valid commit
	git-cat-file commit "$target" > /dev/null || exit 1

	# Do it
	git-read-tree -m -u HEAD $target &&
		(echo $target > .git/HEAD)

and then you can add some fancy flags or whatever.

> - bk export -tpatch -r<rev>

This one is trivial.

	git-diff-tree --pretty $rev

does exactly that: it shows a single revision, with a pretty changelog.

And if you want to get diffs or ranges, use

	git diff rev1..rev2

or similar.

		Linus

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: git Tutorial?
  2005-06-24 16:37     ` git Tutorial? Linus Torvalds
@ 2005-06-25  1:27       ` Patrick Mochel
  0 siblings, 0 replies; 2+ messages in thread
From: Patrick Mochel @ 2005-06-25  1:27 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Git Mailing List


On Fri, 24 Jun 2005, Linus Torvalds wrote:

>
>
> [ git-list cc'd, since these example things might be useful to others ]
>
> On Fri, 24 Jun 2005, Patrick Mochel wrote:

> > The handy things I've noticed missing are the equivalents of
> >
> > - bk changes -u<user> (Great for tracking down a change one did)
>
> You can script it (and if you do so nicely, feel free to send me a
> patch). Here's the magic long-hand version that does something fairly
> close to it:
>
> 	git-rev-list --header HEAD |
> 		grep -z author.*torvalds |
> 		tr '\0\n' '\n:' |
> 		cut -d: -f1 |
> 		git-diff-tree --pretty --stdin -p |
> 		less -S
>
> (That's really hacky, because "cut" and other standard unix tools don't
> like using '\0' as a record separator, but hey, whatever works..)
>
> The above gives the result in "git-whatchanged" format, ie you get the
> patch too. If you don't want to see the patch, give the "-s" flag to
> git-diff-tree instead of the "-p" flag, but if you script it, I'd suggest
> allowing the user to give that as an option to the script.

Ok, it ain't exactly pretty, but it works.

Below is a patch to git-whatchanged that adds some optional parameters to
it that allow users to filter the changesets returned by git-rev-list.

	-a	Specify the author's name.
		This can be any part of the "author" line: the first name,
		the last name, both, the login name, the domain name, or
		the entire email address.

		For example:

		git-whatchanged -a "Linus"
		git-whatchanged -a "Linus Torvalds"
		git-whatchanged -a "torvalds"
		git-whatchanged -a "torvalds@ppc970.osdl.org"
		git-whatchanged -a "@osdl.org"

	-c	Specify the committer's name
		Like the above, this can be any part of the "committer"
		line. For example:

		git-whatchanged -c "Greg"
		git-whatchanged -c "suse.de"
		git-whatchanged -c "gregkh@suse.de"


	And for good measure:

	-s	Specify a person that signed off on a patch.

		git-whatchanged -s "Linus Torvalds"
		git-whatchanged -s "mochel@digitalimplant.org"

		It doesn't support multiple "Signed-off-by" entries.

	They can also be used together:

	git-whatchanged -a mochel@digitalimplant.org -c gregkh@suse.de
	git-whatchanged -a Dunlap -s Torvalds

By default, it still just prints the changeset comments. Passing '-p' will
print the patches.

Please note that my script-fu isn't exactly good, so the patch is probably
done in the worst possible way. Please feel free to rewrite it or simply
just toss it.

Thanks,


	Pat


diff --git a/git-whatchanged b/git-whatchanged
--- a/git-whatchanged
+++ b/git-whatchanged
@@ -1,4 +1,44 @@
 #!/bin/sh
-git-rev-list $(git-rev-parse --default HEAD --revs-only "$@") |
-	git-diff-tree --stdin --pretty -r $(git-rev-parse --no-revs "$@") |
+
+Author=""
+Committer=""
+SignedOffBy=""
+Args=""
+
+while [ $# -gt 0 ] ; do
+
+	echo $1
+case $1 in
+	-a)
+		shift
+		Author="$1"
+		;;
+	-c)
+		shift
+		Committer="$1"
+		;;
+	-s)
+		shift
+		SignedOffBy="$1"
+		;;
+	*)
+		Args="$Args $1"
+		;;
+
+esac
+	shift
+done
+
+filter_cset() {
+	egrep -z "author[[:print:]]+$Author" |
+	egrep -z "committer[[:print:]]+$Committer" |
+	egrep -z "Signed-off-by:[[:print:]]+$SignedOffBy"
+}
+
+
+git-rev-list --header $(git-rev-parse --default HEAD --revs-only "$Args") |
+	filter_cset |
+	tr '\0\n' '\n:' | cut -d: -f1 |
+	git-diff-tree --stdin --pretty $(git-rev-parse --no-revs "$Args") |
 	LESS="$LESS -S" ${PAGER:-less}
+

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-06-25  1:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <Pine.LNX.4.50.0506231808560.721-100000@monsoon.he.net>
     [not found] ` <Pine.LNX.4.58.0506232344431.11175@ppc970.osdl.org>
     [not found]   ` <Pine.LNX.4.50.0506240842090.24799-100000@monsoon.he.net>
2005-06-24 16:37     ` git Tutorial? Linus Torvalds
2005-06-25  1:27       ` Patrick Mochel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.