gpt4 book ai didi

git - 在 git 的命令行中显示 merge 状态的方法

转载 作者:太空狗 更新时间:2023-10-29 13:53:22 24 4
gpt4 key购买 nike

我目前使用以下 bash 脚本将 git 配置为显示我所在的分支(以及我的命令行以显示我所在的目录):

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\] \[\033[33;1m\]\w\[\033[m\] (\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)) \$  \n$ "
export PS2="$ "

我想知道是否有一种方法可以显示“merge ”状态,这样当我 merge 时它也会在命令行中显示 merging(我在哪个分支之后)。我在别处看到过这种情况,所以我很确定这是可能的,但不知道如何实现。

最佳答案

可以在this git-ps1中看到编写一个更完整的状态指示器脚本,其中包含 rebase 和 merge 。

local g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -n "$g" ]; then
local r
local b
if [ -d "$g/rebase-apply" ]
then
if test -f "$g/rebase-apply/rebasing"
then
r="|REBASE"
elif test -f "$g/rebase-apply/applying"
then
r="|AM"
else
r="|AM/REBASE"
fi
b="$(git symbolic-ref HEAD 2>/dev/null)"
elif [ -f "$g/rebase-merge/interactive" ]
then
r="|REBASE-i"
b="$(cat "$g/rebase-merge/head-name")"
elif [ -d "$g/rebase-merge" ]
then
r="|REBASE-m"
b="$(cat "$g/rebase-merge/head-name")"
elif [ -f "$g/MERGE_HEAD" ]
then
r="|MERGING"
b="$(git symbolic-ref HEAD 2>/dev/null)"

对于 merge 部分,它确实会测试 MERGE_HEAD 文件,如 suggested通过 Zeeker .

关于git - 在 git 的命令行中显示 merge 状态的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24690649/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com