Skip to content

Commit ebedc31

Browse files
author
Junio C Hamano
committed
show-branch: make the current branch and merge commits stand out.
This changes the character used to mark the commits that is on the branch from '+' to '*' for the current branch, to make it stand out. Also we show '-' for merge commits. When you have a handful branches with relatively long diversion, it is easier to see which one is the current branch this way. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 54f9734 commit ebedc31

File tree

5 files changed

+64
-49
lines changed

5 files changed

+64
-49
lines changed

Documentation/git-show-branch.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,22 @@ OUTPUT
8181
------
8282
Given N <references>, the first N lines are the one-line
8383
description from their commit message. The branch head that is
84-
pointed at by $GIT_DIR/HEAD is prefixed with an asterisk '*'
85-
character while other heads are prefixed with a '!' character.
84+
pointed at by $GIT_DIR/HEAD is prefixed with an asterisk `*`
85+
character while other heads are prefixed with a `!` character.
8686

8787
Following these N lines, one-line log for each commit is
8888
displayed, indented N places. If a commit is on the I-th
89-
branch, the I-th indentation character shows a '+' sign;
90-
otherwise it shows a space. Each commit shows a short name that
89+
branch, the I-th indentation character shows a `+` sign;
90+
otherwise it shows a space. Merge commits are denoted by
91+
a `-` sign. Each commit shows a short name that
9192
can be used as an extended SHA1 to name that commit.
9293

9394
The following example shows three branches, "master", "fixes"
9495
and "mhf":
9596

9697
------------------------------------------------
9798
$ git show-branch master fixes mhf
98-
! [master] Add 'git show-branch'.
99+
* [master] Add 'git show-branch'.
99100
! [fixes] Introduce "reset type" flag to "git reset"
100101
! [mhf] Allow "+remote:local" refspec to cause --force when fetching.
101102
---
@@ -109,13 +110,13 @@ $ git show-branch master fixes mhf
109110
+ [mhf~6] Retire git-parse-remote.
110111
+ [mhf~7] Multi-head fetch.
111112
+ [mhf~8] Start adding the $GIT_DIR/remotes/ support.
112-
+++ [master] Add 'git show-branch'.
113+
*++ [master] Add 'git show-branch'.
113114
------------------------------------------------
114115

115116
These three branches all forked from a common commit, [master],
116117
whose commit message is "Add 'git show-branch'. "fixes" branch
117118
adds one commit 'Introduce "reset type"'. "mhf" branch has many
118-
other commits.
119+
other commits. The current branch is "master".
119120

120121

121122
EXAMPLE

Documentation/howto/revert-branch-rebase.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ merge introduced 5 commits or so:
3232

3333
------------------------------------------------
3434
$ git show-branch --more=4 master master^2 | head
35-
! [master] Merge refs/heads/portable from http://www.cs.berkeley....
35+
* [master] Merge refs/heads/portable from http://www.cs.berkeley....
3636
! [master^2] Replace C99 array initializers with code.
3737
--
38-
+ [master] Merge refs/heads/portable from http://www.cs.berkeley....
39-
++ [master^2] Replace C99 array initializers with code.
40-
++ [master^2~1] Replace unsetenv() and setenv() with older putenv().
41-
++ [master^2~2] Include sys/time.h in daemon.c.
42-
++ [master^2~3] Fix ?: statements.
43-
++ [master^2~4] Replace zero-length array decls with [].
44-
+ [master~1] tutorial note about git branch
38+
- [master] Merge refs/heads/portable from http://www.cs.berkeley....
39+
*+ [master^2] Replace C99 array initializers with code.
40+
*+ [master^2~1] Replace unsetenv() and setenv() with older putenv().
41+
*+ [master^2~2] Include sys/time.h in daemon.c.
42+
*+ [master^2~3] Fix ?: statements.
43+
*+ [master^2~4] Replace zero-length array decls with [].
44+
* [master~1] tutorial note about git branch
4545
------------------------------------------------
4646

4747
The '--more=4' above means "after we reach the merge base of refs,
@@ -193,8 +193,8 @@ $ git show-branch --more=1 master pu rc
193193
+ [pu~4] Document "git cherry-pick" and "git revert"
194194
+ [pu~5] Remove git-apply-patch-script.
195195
+ [pu~6] Redo "revert" using three-way merge machinery.
196-
+ [rc] Merge refs/heads/master from .
197-
+++ [master] Revert "Replace zero-length array decls with []."
198-
+ [rc~1] Merge refs/heads/master from .
199-
+++ [master~1] Merge refs/heads/portable from http://www.cs.berkeley....
196+
- [rc] Merge refs/heads/master from .
197+
++* [master] Revert "Replace zero-length array decls with []."
198+
- [rc~1] Merge refs/heads/master from .
199+
... [master~1] Merge refs/heads/portable from http://www.cs.berkeley....
200200
------------------------------------------------

Documentation/tutorial.txt

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,8 @@ $ git show-branch master mybranch
968968
* [master] Merge work in mybranch
969969
! [mybranch] Some work.
970970
--
971-
+ [master] Merge work in mybranch
972-
++ [mybranch] Some work.
971+
- [master] Merge work in mybranch
972+
*+ [mybranch] Some work.
973973
------------------------------------------------
974974

975975
The first two lines indicate that it is showing the two branches
@@ -979,7 +979,8 @@ top-of-the-tree commits, you are currently on `master` branch
979979
the later output lines is used to show commits contained in the
980980
`master` branch, and the second column for the `mybranch`
981981
branch. Three commits are shown along with their log messages.
982-
All of them have plus `+` characters in the first column, which
982+
All of them have non blank characters in the first column (`*`
983+
shows an ordinary commit on the current branch, `.` is a merge commit), which
983984
means they are now part of the `master` branch. Only the "Some
984985
work" commit has the plus `+` character in the second column,
985986
because `mybranch` has not been merged to incorporate these
@@ -1024,7 +1025,7 @@ $ git show-branch master mybranch
10241025
! [master] Merge work in mybranch
10251026
* [mybranch] Merge work in mybranch
10261027
--
1027-
++ [master] Merge work in mybranch
1028+
-- [master] Merge work in mybranch
10281029
------------------------------------------------
10291030

10301031

@@ -1199,9 +1200,9 @@ $ git show-branch --more=3 master mybranch
11991200
! [master] Merge work in mybranch
12001201
* [mybranch] Merge work in mybranch
12011202
--
1202-
++ [master] Merge work in mybranch
1203-
++ [master^2] Some work.
1204-
++ [master^] Some fun.
1203+
-- [master] Merge work in mybranch
1204+
+* [master^2] Some work.
1205+
+* [master^] Some fun.
12051206
------------
12061207

12071208
Remember, before running `git merge`, our `master` head was at
@@ -1223,8 +1224,8 @@ $ git show-branch
12231224
! [mybranch] Some work.
12241225
--
12251226
+ [mybranch] Some work.
1226-
+ [master] Some fun.
1227-
++ [mybranch^] New day.
1227+
* [master] Some fun.
1228+
*+ [mybranch^] New day.
12281229
------------
12291230

12301231
Now we are ready to experiment with the merge by hand.
@@ -1743,8 +1744,8 @@ $ git show-branch
17431744
+ [diff-fix] Fix rename detection.
17441745
+ [diff-fix~1] Better common substring algorithm.
17451746
+ [commit-fix] Fix commit message normalization.
1746-
+ [master] Release candidate #1
1747-
+++ [diff-fix~2] Pretty-print messages.
1747+
* [master] Release candidate #1
1748+
++* [diff-fix~2] Pretty-print messages.
17481749
------------
17491750

17501751
Both fixes are tested well, and at this point, you want to merge
@@ -1764,13 +1765,13 @@ $ git show-branch
17641765
! [diff-fix] Fix rename detection.
17651766
* [master] Merge fix in commit-fix
17661767
---
1767-
+ [master] Merge fix in commit-fix
1768-
+ + [commit-fix] Fix commit message normalization.
1769-
+ [master~1] Merge fix in diff-fix
1770-
++ [diff-fix] Fix rename detection.
1771-
++ [diff-fix~1] Better common substring algorithm.
1772-
+ [master~2] Release candidate #1
1773-
+++ [master~3] Pretty-print messages.
1768+
- [master] Merge fix in commit-fix
1769+
+ * [commit-fix] Fix commit message normalization.
1770+
- [master~1] Merge fix in diff-fix
1771+
+* [diff-fix] Fix rename detection.
1772+
+* [diff-fix~1] Better common substring algorithm.
1773+
* [master~2] Release candidate #1
1774+
++* [master~3] Pretty-print messages.
17741775
------------
17751776

17761777
However, there is no particular reason to merge in one branch
@@ -1797,12 +1798,12 @@ $ git show-branch
17971798
! [diff-fix] Fix rename detection.
17981799
* [master] Octopus merge of branches 'diff-fix' and 'commit-fix'
17991800
---
1800-
+ [master] Octopus merge of branches 'diff-fix' and 'commit-fix'
1801-
+ + [commit-fix] Fix commit message normalization.
1802-
++ [diff-fix] Fix rename detection.
1803-
++ [diff-fix~1] Better common substring algorithm.
1804-
+ [master~1] Release candidate #1
1805-
+++ [master~2] Pretty-print messages.
1801+
- [master] Octopus merge of branches 'diff-fix' and 'commit-fix'
1802+
+ * [commit-fix] Fix commit message normalization.
1803+
+* [diff-fix] Fix rename detection.
1804+
+* [diff-fix~1] Better common substring algorithm.
1805+
* [master~1] Release candidate #1
1806+
++* [master~2] Pretty-print messages.
18061807
------------
18071808

18081809
Note that you should not do Octopus because you can. An octopus

show-branch.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ int main(int ac, char **av)
545545
int sha1_name = 0;
546546
int shown_merge_point = 0;
547547
int topo_order = 0;
548+
int head_at = -1;
548549

549550
git_config(git_show_branch_config);
550551
setup_git_directory();
@@ -675,6 +676,8 @@ int main(int ac, char **av)
675676
}
676677
/* header lines never need name */
677678
show_one_commit(rev[i], 1);
679+
if (is_head)
680+
head_at = i;
678681
}
679682
if (0 <= extra) {
680683
for (i = 0; i < num_rev; i++)
@@ -703,9 +706,19 @@ int main(int ac, char **av)
703706
shown_merge_point |= ((this_flag & all_revs) == all_revs);
704707

705708
if (1 < num_rev) {
706-
for (i = 0; i < num_rev; i++)
707-
putchar((this_flag & (1u << (i + REV_SHIFT)))
708-
? '+' : ' ');
709+
int is_merge = !!(commit->parents && commit->parents->next);
710+
for (i = 0; i < num_rev; i++) {
711+
int mark;
712+
if (!(this_flag & (1u << (i + REV_SHIFT))))
713+
mark = ' ';
714+
else if (is_merge)
715+
mark = '-';
716+
else if (i == head_at)
717+
mark = '*';
718+
else
719+
mark = '+';
720+
putchar(mark);
721+
}
709722
putchar(' ');
710723
}
711724
show_one_commit(commit, no_name);

t/t1200-tutorial.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ cat > show-branch.expect << EOF
118118
* [master] Merged "mybranch" changes.
119119
! [mybranch] Some work.
120120
--
121-
+ [master] Merged "mybranch" changes.
122-
++ [mybranch] Some work.
121+
- [master] Merged "mybranch" changes.
122+
*+ [mybranch] Some work.
123123
EOF
124124

125125
git show-branch --topo-order master mybranch > show-branch.output
@@ -142,7 +142,7 @@ cat > show-branch2.expect << EOF
142142
! [master] Merged "mybranch" changes.
143143
* [mybranch] Merged "mybranch" changes.
144144
--
145-
++ [master] Merged "mybranch" changes.
145+
-- [master] Merged "mybranch" changes.
146146
EOF
147147

148148
git show-branch --topo-order master mybranch > show-branch2.output

0 commit comments

Comments
 (0)