Skip to content

Commit f5e375c

Browse files
author
Junio C Hamano
committed
Clean-up output from "git show-branch" and document it.
When showing only one branch a lot of default output becomes redundant, so clean it up a bit, and document what is shown. Retire the earlier implementation "git-show-branches-script". Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent f76412e commit f5e375c

File tree

6 files changed

+128
-140
lines changed

6 files changed

+128
-140
lines changed

Documentation/git-show-branch.txt

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
git-show-branch(1)
2+
==================
3+
v0.99.4, Aug 2005
4+
5+
NAME
6+
----
7+
git-show-branch - Show branches and their commits.
8+
9+
SYNOPSIS
10+
--------
11+
'git show-branch [--all] [--heads] [--tags] [--more=<n>] [--merge-base] <reference>...'
12+
13+
DESCRIPTION
14+
-----------
15+
Shows the head commits from the named <reference> (or all refs under
16+
$GIT_DIR/refs/heads), and displays concise list of commit logs
17+
to show their relationship semi-visually.
18+
19+
OPTIONS
20+
-------
21+
<reference>::
22+
Name of the reference under $GIT_DIR/refs/.
23+
24+
--all --heads --tags::
25+
Show all refs under $GIT_DIR/refs, $GIT_DIR/refs/heads,
26+
and $GIT_DIR/refs/tags, respectively.
27+
28+
--more=<n>::
29+
Usually the command stops output upon showing the commit
30+
that is the common ancestor of all the branches. This
31+
flag tells the command to go <n> commits beyond that.
32+
33+
--merge-base::
34+
Instead of showing the commit list, just act like the
35+
'git-merge-base' command except that it can accept more
36+
than two heads.
37+
38+
39+
OUTPUT
40+
------
41+
Given N <references>, the first N lines are the one-line
42+
description from their commit message. The branch head that is
43+
pointed at by $GIT_DIR/HEAD is prefixed with an asterisk '*'
44+
character while other heads are prefixed with a '!' character.
45+
46+
Following these N lines, one-line log for each commit is
47+
displayed, indented N places. If a commit is on the I-th
48+
branch, the I-th indentation character shows a '+' sign;
49+
otherwise it shows a space. Each commit shows a short name that
50+
can be used as an exended SHA1 to name that commit.
51+
52+
The following example shows three branches, "master", "fixes"
53+
and "mhf":
54+
55+
------------------------------------------------
56+
$ git show-branch master fixes mhf
57+
! [master] Add 'git show-branch'.
58+
! [fixes] Introduce "reset type" flag to "git reset"
59+
! [mhf] Allow "+remote:local" refspec to cause --force when fetching.
60+
---
61+
+ [mhf] Allow "+remote:local" refspec to cause --force when fetching.
62+
+ [mhf~1] Use git-octopus when pulling more than one heads.
63+
+ [fixes] Introduce "reset type" flag to "git reset"
64+
+ [mhf~2] "git fetch --force".
65+
+ [mhf~3] Use .git/remote/origin, not .git/branches/origin.
66+
+ [mhf~4] Make "git pull" and "git fetch" default to origin
67+
+ [mhf~5] Infamous 'octopus merge'
68+
+ [mhf~6] Retire git-parse-remote.
69+
+ [mhf~7] Multi-head fetch.
70+
+ [mhf~8] Start adding the $GIT_DIR/remotes/ support.
71+
+++ [master] Add 'git show-branch'.
72+
------------------------------------------------
73+
74+
These three branches all forked from a common commit, [master],
75+
whose commit message is "Add 'git show-branch'. "fixes" branch
76+
adds one commit 'Introduce "reset type"'. "mhf" branch has many
77+
other commits.
78+
79+
When only one head is given, the output format changes slightly
80+
to conserve space. The '+' sign to show which commit is
81+
reachable from which head and the first N lines to show the list
82+
of heads being displayed are both meaningless so they are
83+
omitted. Also the label given to each commit does not repeat
84+
the name of the branch because it is obvious.
85+
86+
------------------------------------------------
87+
$ git show-branch --more=4 master
88+
[master] Add 'git show-branch'.
89+
[~1] Add a new extended SHA1 syntax <name>~<num>
90+
[~2] Fix "git-diff-script A B"
91+
[~3] git-ls-files: generalized pathspecs
92+
[~4] Make "git-ls-files" work in subdirectories
93+
------------------------------------------------
94+
95+
Author
96+
------
97+
Written by Junio C Hamano <junkio@cox.net>
98+
99+
100+
Documentation
101+
--------------
102+
Documentation by Junio C Hamano.
103+
104+
105+
GIT
106+
---
107+
Part of the link:git.html[git] suite

Documentation/git-show-branches-script.txt

Lines changed: 0 additions & 71 deletions
This file was deleted.

Documentation/git.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ link:git-pull-script.html[git-pull-script]::
208208
link:git-commit-script.html[git-commit-script]::
209209
Record changes to the repository.
210210

211-
link:git-show-branches-script.html[git-show-branches-script]::
211+
link:git-show-branch.html[git-show-branch]::
212212
Show branches and their commits.
213213

214214
link:git-repack-script.html[git-repack-script]::

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ SCRIPTS=git git-apply-patch-script git-merge-one-file-script git-prune-script \
7171
SCRIPTS += git-count-objects-script
7272
# SCRIPTS += git-send-email-script
7373
SCRIPTS += git-revert-script
74-
SCRIPTS += git-show-branches-script
7574

7675
PROG= git-update-cache git-diff-files git-init-db git-write-tree \
7776
git-read-tree git-commit-tree git-cat-file git-fsck-cache \

git-show-branches-script

Lines changed: 0 additions & 61 deletions
This file was deleted.

show-branch.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ int main(int ac, char **av)
223223
int head_path_len;
224224
unsigned char head_sha1[20];
225225
int merge_base = 0;
226+
char **label;
226227

227228
while (1 < ac && av[1][0] == '-') {
228229
char *arg = av[1];
@@ -297,7 +298,8 @@ int main(int ac, char **av)
297298
if (merge_base)
298299
return show_merge_base(seen, num_rev);
299300

300-
if (1 < num_rev)
301+
/* Show list */
302+
if (1 < num_rev) {
301303
for (i = 0; i < num_rev; i++) {
302304
int j;
303305
int is_head = rev_is_head(head_path,
@@ -310,16 +312,28 @@ int main(int ac, char **av)
310312
printf("%c [%s] ", is_head ? '*' : '!', ref_name[i]);
311313
show_one_commit(rev[i], NULL);
312314
}
315+
for (i = 0; i < num_rev; i++)
316+
putchar('-');
317+
putchar('\n');
318+
}
319+
320+
label = ref_name;
313321
while (seen) {
314322
struct commit *commit = pop_one_commit(&seen);
315323
int this_flag = commit->object.flags;
324+
static char *obvious[] = { "" };
325+
316326
if ((this_flag & UNINTERESTING) && (--extra < 0))
317327
break;
318-
for (i = 0; i < num_rev; i++)
319-
putchar((this_flag & (1u << (i + REV_SHIFT)))
320-
? '+' : ' ');
321-
putchar(' ');
322-
show_one_commit(commit, ref_name);
328+
if (1 < num_rev) {
329+
for (i = 0; i < num_rev; i++)
330+
putchar((this_flag & (1u << (i + REV_SHIFT)))
331+
? '+' : ' ');
332+
putchar(' ');
333+
}
334+
show_one_commit(commit, label);
335+
if (num_rev == 1)
336+
label = obvious;
323337
}
324338
return 0;
325339
}

0 commit comments

Comments
 (0)