git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [howto] Kernel hacker's guide to git, updated

From
Junio C Hamano <junkio@cox.net>
Date
Oct 2, 2005, 08:47 UTC
Message-ID
<7vr7b41f1f.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<433D477A.4010009@pobox.com>
Jeff Garzik <jgarzik@pobox.com> writes:
> Junio C Hamano wrote:
>> Jeff Garzik <jgarzik@pobox.com> writes:
>>> 2) What is the easiest way to obtain a list of changes present in
>>> repository B, that are not present in repository A?  I used to use
>>> git-changes-script [hacked cg-log script] for this:

I haven't really *read* that script, but I think it is trying to make a list of commits from both repositories and trying to find the set that are in one side and not in the other using diff (a real shell programer probably would have used "comm" for this kind of task, not "diff"), then doing a handcrafted git-log on each of them.

Attached is my quick hack, based on your original question, without really trying to understand what the script is doing, so I cannot claim it is a rewrite nor even attempting to be compatible. Please take a look at it and tell me if this is any close to what you need.

I have a suspition that this might be better done as a natural extension of git-log, though.

------------ #!/bin/sh # # Copyright (c) 2005 Junio C Hamano #

. git-sh-setup || die "Not a git archive"
usage () {
	echo >&2 "$0 ( -L | -R ) <dir> [<ref>] [<ref>]

-L shows changes in local not in remote. -R shows changes in remote not in local. <dir> names the remote repository.

If given no refs, local and remote HEADs are compared.
If given one ref, local HEAD and named remote ref are compared.
If given two refs, the first names a local ref, and the second names
remote ref to be compared.
"
	exit 1
}
case "$1" in
-L | -R)
	;;
*)
	usage ;;
esac
other="$2"
(
	unset GIT_DIR GIT_OBJECT_DIRECTORY
	cd "$other" && . git-sh-setup ||
	die "$other is not a valid git repository."
)

local=${3:-HEAD} remote=${4:-HEAD}

# Basic validation. local=$(git-rev-parse --verify "$local^0" 2>/dev/null) || die "local ref $local is not valid." remote=$(GIT_DIR="$other" git-rev-parse --verify "$remote^0" 2>/dev/null) || die "remote ref $remote is not valid."

case "$1" in
-L)
	list_args="$local ^$remote" ;;
-R)
	list_args="^$local $remote" ;;
esac
GAOD="$GIT_ALTERNATE_OBJECT_DIRECTORIES"

GIT_ALTERNATE_OBJECT_DIRECTORIES="$other/.git/objects:$GAOD" \ git-rev-list --pretty $list_args | LESS=-S ${PAGER:-less}

Previous: Jeff GarzikNext: Linus Torvalds
Message 31 of 40 in “[howto] Kernel hacker's guide to git, updated”
  1. Jeff GarzikSep 29, 2005
  2. David LeimbachSep 29, 2005
  3. Alberto PatinoSep 29, 2005
  4. David LeimbachSep 29, 2005
  5. Oliver NeukumSep 29, 2005
  6. Jon LoeligerSep 29, 2005
  7. Oliver NeukumSep 29, 2005
  8. Junio C HamanoSep 30, 2005
  9. Oliver NeukumSep 30, 2005
  10. Linus TorvaldsSep 30, 2005
  11. Dave JonesSep 29, 2005
  12. Anton AltaparmakovSep 29, 2005
  13. Dave JonesSep 29, 2005
  14. Linus TorvaldsSep 29, 2005
  15. Linus TorvaldsSep 29, 2005
  16. Dave JonesSep 29, 2005
  17. Linus TorvaldsSep 29, 2005
  18. Anton AltaparmakovSep 29, 2005
  19. Linus TorvaldsSep 29, 2005
  20. Anton AltaparmakovSep 29, 2005
  21. Junio C HamanoSep 29, 2005
  22. Johannes SchindelinSep 30, 2005
  23. Elfyn McBratneySep 29, 2005
  24. Linus TorvaldsSep 29, 2005
  25. Dave JonesSep 29, 2005
  26. Jeff GarzikSep 29, 2005
  27. Junio C HamanoSep 29, 2005
  28. Jeff GarzikSep 30, 2005
  29. Junio C HamanoSep 30, 2005
  30. Jeff GarzikSep 30, 2005
  31. Junio C HamanoOct 2, 2005
  32. Linus TorvaldsSep 30, 2005
  33. Junio C HamanoOct 1, 2005
  34. Oliver NeukumSep 30, 2005
  35. Jeff GarzikSep 30, 2005
  36. Alberto PatinoSep 30, 2005
  37. Erik MouwSep 30, 2005
  38. Jeff GarzikSep 30, 2005
  39. Francois RomieuSep 30, 2005
  40. Chuck LeverSep 29, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.