From: Linus Torvalds <torvalds@osdl.org>
To: Patrick Mochel <mochel@digitalimplant.org>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: git Tutorial?
Date: Fri, 24 Jun 2005 09:37:06 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.58.0506240910040.11175@ppc970.osdl.org> (raw)
In-Reply-To: <Pine.LNX.4.50.0506240842090.24799-100000@monsoon.he.net>
[ 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
next parent reply other threads:[~2005-06-24 16:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 ` Linus Torvalds [this message]
2005-06-25 1:27 ` git Tutorial? Patrick Mochel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.58.0506240910040.11175@ppc970.osdl.org \
--to=torvalds@osdl.org \
--cc=git@vger.kernel.org \
--cc=mochel@digitalimplant.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox