如何知道git rebase是否正在进行中?

时间:2010-10-13 06:58:11

标签: git git-rebase

当我开始git rebase -i时,我可以发出git rebase --continuegit rebase --abort等命令。这些命令仅在重组正在进行时才有效。

我如何知道是否有正在进行的变基?

(我非常感谢关于rebase如何在内部工作的一些细节; git对一个让它具有“rebase in progress”状态的repo做了什么,?)

8 个答案:

答案 0 :(得分:47)

首先,在rebase期间 there is a ORIG_HEAD (但不限于rebase命令)

但你也可以看一下2010 Git 1.7.0 git-rebase.sh script 本身(你可以得到“内部”)。) 像这样的线可以给你另一条线索:

dotest="$GIT_DIR"/rebase-merge
test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || die "No rebase in progress?"

sabgenton comments

  • 文件夹rebase-apply似乎与rebase
  • 一起显示
  • 但文件夹rebase-merge仅显示rebase -i

2017年,hippycomments

  

编码指南不鼓励使用-o(请参阅Documentation/CodingGuidelines),因此now (2017, but also since 2011, Git 1.7.6)的正确方法是:

(test -d ".git/rebase-merge" || test -d ".git/rebase-apply") || die "No rebase in progress?"

Jelaby建议in the comments

(test -d "$(git rev-parse --git-path rebase-merge)" || \
 test -d "$(git rev-parse --git-path rebase-apply)" )
  

这可以正确处理没有.git目录的工作树和异常或非标准布局,还允许您从工作目录的子目录运行此测试。

这是因为git rev-parse --git-path <path>:确实解析了“$GIT_DIR/<path>”。


Git 2.6 +(2015年第3季度)将在rebase期间打印更多信息:

请参阅commit 592e412commit 84e6fb9(2015年7月6日),commit 84e6fb9(2015年7月6日)和commit df25e94commit 05eb563(2015年6月30日) Guillaume Pagès (gitster)
(由Junio C Hamano -- gitster --合并于commit 178d2c7,2015年8月3日)

  

status:在rebase -i

期间提供更多信息      

git statusrebase -i期间提供了有关在rebase期间完成的命令列表的更多信息。
  它显示:

     
      
  • 执行的最后两个命令和
  •   
  • 接下来要执行的两行。
  •   
     

它还提供了在.git目录中查找整个文件的提示。

答案 1 :(得分:16)

您还可以在__git_ps1 function in contrib/completion/git-prompt.sh中检查这种检测是如何完成的,可以用于git-aware bash提示:

                if [ -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")"
                else
                        if [ -d "$g/rebase-apply" ]; then
                                if [ -f "$g/rebase-apply/rebasing" ]; then
                                        r="|REBASE"
                                elif [ -f "$g/rebase-apply/applying" ]; then
                                        r="|AM"
                                else
                                        r="|AM/REBASE"
                                fi

答案 2 :(得分:3)

如果正在进行交互式rebase,这将告诉您您在此过程中的位置:

$ cat .git/rebase-merge/done 
pick 786139e lrg
edit 668b8a6 ktio
$ 

现在我正在编辑交互式rebase中的“ktio”补丁。

如果没有重组,它将如下所示:

$ cat .git/rebase-merge/done 
cat: .git/rebase-merge/done: No such file or directory
$ 

答案 3 :(得分:3)

如果您有EasyGiteg status会告诉您:

$ eg status
(Not currently on any branch.)
(YOU ARE IN THE MIDDLE OF A INTERACTIVE REBASE; RUN 'eg help topic middle-of-rebase' FOR MORE INFO.)
Changes ready to be committed ("staged"):
    modified:   .gitmodules
    renamed:    config_loader.rb -> code/config_loader.rb
Newly created unknown files:
    vendor/
(YOU ARE IN THE MIDDLE OF A INTERACTIVE REBASE; RUN 'eg help topic middle-of-rebase' FOR MORE INFO.)

在彩色终端中,通知非常突出:

<code>eg status</code> middle-of-rebase demonstration screenshot

eg help topic middle-of-rebase显示文档“How to resolve or abort an incomplete rebase”。)

答案 4 :(得分:3)

从bash命令行:

ls `git rev-parse --git-dir` | grep rebase

如果存在rebase文件夹,则返回退出代码0(成功),并将defase文件夹输出到STDOUT。如果您在rebase中间,那么它将不输出任何内容并返回非0退出代码。所以你甚至可以这样做:

ls `git rev-parse --git-dir` | grep rebase || echo no rebase

答案 5 :(得分:1)

我正在使用此命令is_rebase=$(git status | grep "rebasing" | wc -l)

答案 6 :(得分:1)

这里有一些不好的答案。 git 并没有真正说明它应该如何工作,所以唯一的答案是“git 是如何做到的?”。代码是here

int wt_status_check_rebase(const struct worktree *wt,
               struct wt_status_state *state)
{
    struct stat st;

    if (!stat(worktree_git_path(wt, "rebase-apply"), &st)) {
        if (!stat(worktree_git_path(wt, "rebase-apply/applying"), &st)) {
            state->am_in_progress = 1;
            if (!stat(worktree_git_path(wt, "rebase-apply/patch"), &st) && !st.st_size)
                state->am_empty_patch = 1;
        } else {
            state->rebase_in_progress = 1;
            state->branch = get_branch(wt, "rebase-apply/head-name");
            state->onto = get_branch(wt, "rebase-apply/onto");
        }
    } else if (!stat(worktree_git_path(wt, "rebase-merge"), &st)) {
        if (!stat(worktree_git_path(wt, "rebase-merge/interactive"), &st))
            state->rebase_interactive_in_progress = 1;
        else
            state->rebase_in_progress = 1;
        state->branch = get_branch(wt, "rebase-merge/head-name");
        state->onto = get_branch(wt, "rebase-merge/onto");
    } else
        return 0;
    return 1;
}

它主要检查这几个文件/目录是否存在(注意 !stat() 表示“文件是否存在”)。 amgit am,用于从邮箱应用补丁,我怀疑除了 Linux 开发人员使用的任何人。

  • rebase_in_progress.git/rebase-apply && !.git/rebase-apply/applying || .git/rebase-merge && !.git/rebase-merge/interactive
  • interactive_rebase_in_progress.git/rebase-merge && .git/rebase-merge/interactive
  • am_in_progress.git/rebase-apply && .git/rebase-apply/applying

我想如果您想知道是否发生了任何类型的 rebase/am,只需检查 .git/rebase-apply.git/rebase-merge 是否存在。

答案 7 :(得分:0)

我还没有看到清楚的陈述,所以这里是:

在重新定标过程中,如果正在进行中,git status就足够了,因为它可以提供信息(供参考,我分别名为masterrbBr的枫枝分支):< / p>

interactive rebase in progress; onto 5f8e534
Last command done (1 command done):
   pick 1b7a450 BRANCH: another comment
No commands remaining.
You are currently rebasing branch 'rbBr' on '5f8e534'.
  (fix conflicts and then run "git rebase --continue")
  (use "git rebase --skip" to skip this patch)
  (use "git rebase --abort" to check out the original branch)

Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
        both modified:   User.java

no changes added to commit (use "git add" and/or "git commit -a")

在解决冲突之前显示此内容,在解决冲突之后显示:

interactive rebase in progress; onto 5f8e534
Last command done (1 command done):
   pick 1b7a450 BRANCH: another comment
No commands remaining.
You are currently rebasing branch 'rbBr' on '5f8e534'.
  (all conflicts fixed: run "git rebase --continue")

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   User.java

PS C:\my_git_repos\learning_git> git rebase --continue                                                                                                                                                                                       [detached HEAD 9645135] BRANCH: another comment
 1 file changed, 1 insertion(+)
Successfully rebased and updated refs/heads/rbBr.
相关问题