做`git log --graph`时如何折叠分支?

时间:2019-10-30 11:55:41

标签: git

使用WITH YourTable AS (SELECT ',1,,3,,Mango,.,.,Apple,Orange' AS InputString, 'MangoAppleOrange' AS ExecptedString UNION ALL SELECT ',,,99,,,Apple,.,.,,Mango,,,Grape,,', 'AppleMangoGrape' UNION ALL SELECT ',,,99,,-,Banana,/....*,.,,Mango,,,Grape,,', 'BananaMangoGrape') SELECT YT.InputString, (SELECT '' + NG.token FROM dbo.NGrams8k(YT.InputString,1) NG WHERE NG.token LIKE '[A-z]' ORDER BY NG.position ASC FOR XML PATH(''),TYPE).value('.','varchar(MAX)') AS NewString FROM YourTable YT; 时是否可以折叠完全合并的分支?

而不是显示git log --graph

git log --graph --branches

由于分支* 16bb2c5 (HEAD, dev) Merge branch f |\ | * 4571fbd Commit 14 | * de845ac Commit 13 |/ | * aba23a5 (branch e) Commit 12 |/ * 305d031 Merge branch c |\ | | * 80c47c6 (branch d) Commit 11 | | * dbc182e Commit 10 | | * 18bb013 Commit 9 | |/ | * 879e64a Commit 8 | * b9a1413 Commit 7 | * ddd92f9 Commit 6 |/ * 2e94cc8 Merge branch b |\ | * 852ddaf Commit 5 | * 88cdaf9 Commit 4 | * d1d7c7b Commit 3 |/ | * bd1557a (branch a) Commit 2 |/ o e740474 (master) Commit 1 a已完全合并(并删除,因此c不会尝试显示它们),我希望拥有(有或没有{{ 1}}条评论):

--branches

我的用例如下。我想有一个别名来显示我尚未合并的所有本地提交,从本地分支列表开始,从master开始,除非它们不是dev的第一个父级的后代。编辑:目标是区分什么是集成的,什么仍在进行中。

请注意,# COLLAPSED显示我想要的所有提交,但不包括所有提交的所有可见父级之间的链接(* 16bb2c5 (HEAD, dev) Merge branch f ### COLLAPSED | * aba23a5 (branch e) Commit 12 |/ * 305d031 Merge branch c |\ | | * 80c47c6 (branch d) Commit 11 | | * dbc182e Commit 10 | | * 18bb013 Commit 9 | |/ | * 879e64a Commit 8 ### DO NOT COLLAPSE THOSE COMMITS SINCE BRANCH D ISN'T MERGED | * b9a1413 Commit 7 | * ddd92f9 Commit 6 |/ * 2e94cc8 Merge branch b ### COLLAPSED | * bd1557a (branch a) Commit 2 |/ o e740474 (master) Commit 1 并未链接为{{1 }}。

git log --graph --branches --first-parent

2 个答案:

答案 0 :(得分:0)

  

我尚未推送的所有本地提交

对于您的查询可能有一个精确的答案,但是您应该避免未推送本地提交。依靠这些未经推动的承诺而不松懈的工作似乎不是一种可持续的解决方案。

更好的策略可能是比较分支机构,并以该信息为基础来决定需要整合哪些内容。

这样,您可以推送所有内容(是的!现在很安全)。


前进/后退

您可以结帐git ahead/behind info between master and branch?

一些在线工具“免费”为您提供每个分支机构的领先/落后:

enter image description here

答案 1 :(得分:0)

我发现了一种很简单的方法(它支持颜色)。

我在~/.gitconfig

中添加了以下别名
graph = !sh -c '~/scripts/gitgraph --boundary master..  "$@"' -

然后我在~/scripts/gitgraph

中创建了以下脚本
#!/usr/bin/env sh
# Display a graph of all umerged branches
# All arguments will be passed to git log

# Use color if output is not connected to a terminal
COLOR=''
[ -t 1 ] && COLOR='--color'

# Note: each ASCII_CODES create two capture group
ASCII_CODES="$(printf "\\\\(\\\\(\033\\\\[[^m]*m\\\\)*\\\\)")"·

#1: Replace color of |\ and |/
#2: Display first-parents
#3: Display non-merged commits whitch aren't first-parents
#4: Replace commit message of merged commits witch aren't first parents with "..."
#uniq: Squash multiples consecutive lines created by #4
git log --graph --oneline --decorate --branches ${COLOR} "$@" | sed -n \
    -e "s/^${ASCII_CODES}|${ASCII_CODES}\\([\\\\\\/]\\)${ASCII_CODES} */\\1|\\5\\6/p" \
    -e "/^${ASCII_CODES}|${ASCII_CODES}\\\\/ , /^${ASCII_CODES}|${ASCII_CODES}\\// "'!p' \
    -e "/^${ASCII_CODES}|${ASCII_CODES}\\\\/ , /^${ASCII_CODES}|${ASCII_CODES}\\// { /^${ASCII_CODES}|${ASCII_CODES} \\*/"' !p }' \
    -e "/^${ASCII_CODES}|${ASCII_CODES}\\\\/ , /^${ASCII_CODES}|${ASCII_CODES}\\// { s/^${ASCII_CODES}|${ASCII_CODES} \\*.*/\\1| ...\\3/p }" \
| uniq 

示例(注意:前缀#1至#4对应于sed中将对其进行修改的行)

#1 * 87842c1 Commit 17
#1 * 1ab18c1 Commit 16
#1 *   16bb2c5 (HEAD, dev) Merge branch f
#2 |\
#4 | * 4571fbd Commit 15
#4 | * de845ac Commit 14
#2 |/
#3 | * 12afeee (branch e) Commit 13
#3 | * aba23a5 Commit 12
#2 |/
#1 *   305d031 Merge branch c
#2 |\
#3 | | * 80c47c6 (branch d) Commit 11
#3 | | * dbc182e Commit 10
#3 | | * 18bb013 Commit 9
#3 | |/
#4 | * 879e64a Commit 8
#4 | * b9a1413 Commit 7
#4 | * ddd92f9 Commit 6
#2 |/
#1 *   2e94cc8 Merge branch b

将成为

* 87842c1 Commit 17
* 1ab18c1 Commit 16
*   16bb2c5 (HEAD, dev) Merge branch f
|\
| * 4571fbd Commit 15
| * de845ac Commit 14
|/
| * 12afeee (branch e) Commit 13
| * aba23a5 Commit 12
|/
*   305d031 Merge branch c
|\
| | * 80c47c6 (branch d) Commit 11
| | * dbc182e Commit 10
| | * 18bb013 Commit 9
| |/
| * ...
|/
*   2e94cc8 Merge branch b