陈旧分支合并到分支主分支中最常用的健康程序员工作流程是什么?
What is the most used healthy programmer's workflow for stale branches' merging into branch main?
我有很多陈旧的分支,我希望保留一些作为存档,让其他人将它们合并到主分支中。但是它们在 git log --graph --oneline --all
视图中形成了如此多的线程,因此我需要一个更直观的工具,或者更适合的算法。我会使用 SourceTree 来显示其多彩的分支,但它在 Linux.
上不可用
我有可视化工具,但我觉得如果没有用户手册,我无法从中获得最佳结果(例如 VS Code 的 GitLens 扩展)。就像我有自由,但我的大脑中没有形成使用模式。我可以尝试几个月或几年来解决我脑海中的这种混乱,但我更愿意问。
我必须说,通过术语“健康”,我可能在某些情况下也理解“高效”。
我用伪代码描述我想要的:
for each not-merged-into-A branch X (A is another branch)
start a group
show branch X's name
for each not-merged-into-A commit Y in X, fixed order (ascending or descending)
start a subgroup
show commit ID Y
for each changed file Z in Y, grouped by parent path, fixed order (lexicographically)
in column 1 show relative file path for Z
in column 2 show the change that occurred to Z, eventually colorfully and hopefully with changes counters
end the subgroup
end the group
术语“组”是指视觉上分离的输出区域。
我不介意它是否可以在 VS Code 中使用一些可用的扩展来完成。
谢谢。
git log
有很多(很多很多)选项,其中:
--simplify-by-decoration
: 允许更紧凑地查看您的历史记录
--decorate-refs
:与上述结合使用时,允许您 select 保留一些引用(例如:仅分支,仅标记,仅以 feature/
开头的分支 ... )
--name-only
或 --name-status
:显示结果图中显示的两次提交之间修改的文件列表
您可以使用 :
列出尚未合并到 master 中的分支(或引用)
git branch --no-merged master
git for-each-ref --no-merged master
仅在一个显示中处理许多分支可能仍然太多,但上述选项可能会帮助您使用对 git log master that/branch
.
的隔离调用来获得您想要的内容
另请注意:--name-only
和 --name-status
是 git diff
的有效选项
# the following will show the list of files modified by my/branch
# since it forked from master (<- 3 dots between the two names)
git diff --name-status master...my/branch
示例:使用 git 的存储库(镜像在 github.com/git/git
)
- 使用
--simplify-by-decoration
,git log
将输出一个简化的图表,其中显示的唯一提交是:
- ref 指向的提交(例如:分支、标记或远程分支)
- 此类引用的分支和合并点
$ git log --graph --oneline --all --simplify-by-decoration
* 33bc620fd1 (origin/seen) Merge branch 'ab/config-based-hooks-base' into seen
* 670b81a890 (HEAD -> master, origin/next, origin/master, origin/HEAD) The second batch
* ebf3c04b26 (tag: v2.32.0, origin/maint) Git 2.32
* c09b6306c6 (tag: v2.32.0-rc3) Git 2.32-rc3
* 4e42405f00 (tag: v2.32.0-rc2) Git 2.32-rc2
* de88ac70f3 (tag: v2.32.0-rc1) Git 2.32-rc1
* bf949ade81 (tag: v2.32.0-rc0) Git 2.32-rc0
* 48bf2fa8ba (tag: v2.31.1) Git 2.31.1
* a5828ae6b5 (tag: v2.31.0) Git 2.31
* 13d7ab6b5d (tag: v2.31.0-rc2) Git 2.31-rc2
* 56a57652ef Sync with Git 2.30.2 for CVE-2021-21300
|\
| * 94f6e3e283 (tag: v2.30.2) Git 2.30.2
| * e4e68081bb Sync with 2.29.3
- 使用
--decorate-refs=<pattern>
,您可以限制要查看的参考列表:
# only see remote branches :
$ git log --oneline --graph --all --simplify-by-decoration \
--decorate-refs=refs/remotes/origin
* 33bc620fd1 (origin/seen) Merge branch 'ab/config-based-hooks-base' into seen
* 670b81a890 (origin/next, origin/master, origin/HEAD) The second batch
* ebf3c04b26 (origin/maint) Git 2.32
| * 2cbe4a3e12 (origin/todo) What's cooking (2021/06 #06)
| * ee21229929 Merge in "What's cooking" history
| |\
| | * 7d77f2e9cc What's cooking (2008/06 #01)
| * 1bd90415de Keep track of to-do document.
# only see local branches (note : I only checked out 'master' and 'todo' locally)
# and tags starting with 'v2.32.' :
$ git log --oneline --graph --all --simplify-by-decoration \
--decorate-refs=refs/heads --decorate-refs=refs/tags/v2.32.*
* 670b81a890 (master) The second batch
* ebf3c04b26 (tag: v2.32.0) Git 2.32
* c09b6306c6 (tag: v2.32.0-rc3) Git 2.32-rc3
* 4e42405f00 (tag: v2.32.0-rc2) Git 2.32-rc2
* de88ac70f3 (tag: v2.32.0-rc1) Git 2.32-rc1
* bf949ade81 (tag: v2.32.0-rc0) Git 2.32-rc0
| * 2cbe4a3e12 (todo) What's cooking (2021/06 #06)
| * ee21229929 Merge in "What's cooking" history
| |\
| | * 7d77f2e9cc What's cooking (2008/06 #01)
| * 1bd90415de Keep track of to-do document.
- 如果您添加
--name-status
,您将看到已修改文件的列表:
$ git log --graph --oneline --name-status --all --simplify-by-decoration
* 670b81a890 (master) The second batch
| M Documentation/Makefile
| A Documentation/RelNotes/2.33.0.txt
| M Documentation/config/color.txt
| M Documentation/diff-options.txt
...
| M t/test-lib.sh
| M trace2/tr2_dst.c
| M transport.c
* ebf3c04b26 (tag: v2.32.0, origin/maint) Git 2.32
| M GIT-VERSION-GEN
| R072 po/README po/README.md
| M po/TEAMS
...
| M po/zh_TW.po
| M t/lib-parallel-checkout.sh
| M write-or-die.c
* c09b6306c6 (tag: v2.32.0-rc3) Git 2.32-rc3
| M GIT-VERSION-GEN
| M builtin/fsck.c
| M contrib/completion/git-completion.bash
| M contrib/completion/git-completion.zsh
* 4e42405f00 (tag: v2.32.0-rc2) Git 2.32-rc2
| M GIT-VERSION-GEN
...
该列表是该图中显示的两次提交之间修改的文件列表。
例如:提交670b81
修改的唯一文件(master
的当前状态)是:
$ git show --name-status master
commit 670b81a890388c60b7032a4f5b879f2ece8c4558 (origin/next, origin/master, origin/HEAD, master)
Author: Junio C Hamano <gitster@pobox.com>
Date: Mon Jun 14 13:23:28 2021 +0900
The second batch
Signed-off-by: Junio C Hamano <gitster@pobox.com>
M Documentation/RelNotes/2.33.0.txt
名单:
| M Documentation/Makefile
| A Documentation/RelNotes/2.33.0.txt
| M Documentation/config/color.txt
...
是在master
和tag: v2.32.0
之间修改的文件的完整列表
(你会得到相同的列表:git diff --name-status v2.32.0 master
)。
我有很多陈旧的分支,我希望保留一些作为存档,让其他人将它们合并到主分支中。但是它们在 git log --graph --oneline --all
视图中形成了如此多的线程,因此我需要一个更直观的工具,或者更适合的算法。我会使用 SourceTree 来显示其多彩的分支,但它在 Linux.
我有可视化工具,但我觉得如果没有用户手册,我无法从中获得最佳结果(例如 VS Code 的 GitLens 扩展)。就像我有自由,但我的大脑中没有形成使用模式。我可以尝试几个月或几年来解决我脑海中的这种混乱,但我更愿意问。
我必须说,通过术语“健康”,我可能在某些情况下也理解“高效”。
我用伪代码描述我想要的:
for each not-merged-into-A branch X (A is another branch)
start a group
show branch X's name
for each not-merged-into-A commit Y in X, fixed order (ascending or descending)
start a subgroup
show commit ID Y
for each changed file Z in Y, grouped by parent path, fixed order (lexicographically)
in column 1 show relative file path for Z
in column 2 show the change that occurred to Z, eventually colorfully and hopefully with changes counters
end the subgroup
end the group
术语“组”是指视觉上分离的输出区域。
我不介意它是否可以在 VS Code 中使用一些可用的扩展来完成。
谢谢。
git log
有很多(很多很多)选项,其中:
--simplify-by-decoration
: 允许更紧凑地查看您的历史记录--decorate-refs
:与上述结合使用时,允许您 select 保留一些引用(例如:仅分支,仅标记,仅以feature/
开头的分支 ... )--name-only
或--name-status
:显示结果图中显示的两次提交之间修改的文件列表
您可以使用 :
列出尚未合并到 master 中的分支(或引用)git branch --no-merged master
git for-each-ref --no-merged master
仅在一个显示中处理许多分支可能仍然太多,但上述选项可能会帮助您使用对 git log master that/branch
.
另请注意:--name-only
和 --name-status
是 git diff
# the following will show the list of files modified by my/branch
# since it forked from master (<- 3 dots between the two names)
git diff --name-status master...my/branch
示例:使用 git 的存储库(镜像在 github.com/git/git
)
- 使用
--simplify-by-decoration
,git log
将输出一个简化的图表,其中显示的唯一提交是:
- ref 指向的提交(例如:分支、标记或远程分支)
- 此类引用的分支和合并点
$ git log --graph --oneline --all --simplify-by-decoration
* 33bc620fd1 (origin/seen) Merge branch 'ab/config-based-hooks-base' into seen
* 670b81a890 (HEAD -> master, origin/next, origin/master, origin/HEAD) The second batch
* ebf3c04b26 (tag: v2.32.0, origin/maint) Git 2.32
* c09b6306c6 (tag: v2.32.0-rc3) Git 2.32-rc3
* 4e42405f00 (tag: v2.32.0-rc2) Git 2.32-rc2
* de88ac70f3 (tag: v2.32.0-rc1) Git 2.32-rc1
* bf949ade81 (tag: v2.32.0-rc0) Git 2.32-rc0
* 48bf2fa8ba (tag: v2.31.1) Git 2.31.1
* a5828ae6b5 (tag: v2.31.0) Git 2.31
* 13d7ab6b5d (tag: v2.31.0-rc2) Git 2.31-rc2
* 56a57652ef Sync with Git 2.30.2 for CVE-2021-21300
|\
| * 94f6e3e283 (tag: v2.30.2) Git 2.30.2
| * e4e68081bb Sync with 2.29.3
- 使用
--decorate-refs=<pattern>
,您可以限制要查看的参考列表:
# only see remote branches :
$ git log --oneline --graph --all --simplify-by-decoration \
--decorate-refs=refs/remotes/origin
* 33bc620fd1 (origin/seen) Merge branch 'ab/config-based-hooks-base' into seen
* 670b81a890 (origin/next, origin/master, origin/HEAD) The second batch
* ebf3c04b26 (origin/maint) Git 2.32
| * 2cbe4a3e12 (origin/todo) What's cooking (2021/06 #06)
| * ee21229929 Merge in "What's cooking" history
| |\
| | * 7d77f2e9cc What's cooking (2008/06 #01)
| * 1bd90415de Keep track of to-do document.
# only see local branches (note : I only checked out 'master' and 'todo' locally)
# and tags starting with 'v2.32.' :
$ git log --oneline --graph --all --simplify-by-decoration \
--decorate-refs=refs/heads --decorate-refs=refs/tags/v2.32.*
* 670b81a890 (master) The second batch
* ebf3c04b26 (tag: v2.32.0) Git 2.32
* c09b6306c6 (tag: v2.32.0-rc3) Git 2.32-rc3
* 4e42405f00 (tag: v2.32.0-rc2) Git 2.32-rc2
* de88ac70f3 (tag: v2.32.0-rc1) Git 2.32-rc1
* bf949ade81 (tag: v2.32.0-rc0) Git 2.32-rc0
| * 2cbe4a3e12 (todo) What's cooking (2021/06 #06)
| * ee21229929 Merge in "What's cooking" history
| |\
| | * 7d77f2e9cc What's cooking (2008/06 #01)
| * 1bd90415de Keep track of to-do document.
- 如果您添加
--name-status
,您将看到已修改文件的列表:
$ git log --graph --oneline --name-status --all --simplify-by-decoration
* 670b81a890 (master) The second batch
| M Documentation/Makefile
| A Documentation/RelNotes/2.33.0.txt
| M Documentation/config/color.txt
| M Documentation/diff-options.txt
...
| M t/test-lib.sh
| M trace2/tr2_dst.c
| M transport.c
* ebf3c04b26 (tag: v2.32.0, origin/maint) Git 2.32
| M GIT-VERSION-GEN
| R072 po/README po/README.md
| M po/TEAMS
...
| M po/zh_TW.po
| M t/lib-parallel-checkout.sh
| M write-or-die.c
* c09b6306c6 (tag: v2.32.0-rc3) Git 2.32-rc3
| M GIT-VERSION-GEN
| M builtin/fsck.c
| M contrib/completion/git-completion.bash
| M contrib/completion/git-completion.zsh
* 4e42405f00 (tag: v2.32.0-rc2) Git 2.32-rc2
| M GIT-VERSION-GEN
...
该列表是该图中显示的两次提交之间修改的文件列表。
例如:提交670b81
修改的唯一文件(master
的当前状态)是:
$ git show --name-status master
commit 670b81a890388c60b7032a4f5b879f2ece8c4558 (origin/next, origin/master, origin/HEAD, master)
Author: Junio C Hamano <gitster@pobox.com>
Date: Mon Jun 14 13:23:28 2021 +0900
The second batch
Signed-off-by: Junio C Hamano <gitster@pobox.com>
M Documentation/RelNotes/2.33.0.txt
名单:
| M Documentation/Makefile
| A Documentation/RelNotes/2.33.0.txt
| M Documentation/config/color.txt
...
是在master
和tag: v2.32.0
之间修改的文件的完整列表
(你会得到相同的列表:git diff --name-status v2.32.0 master
)。