簡體   English   中英

git branch不應該-不合並列出新的分支嗎?

[英]Shouldn't git branch --no-merged list new branches?

我們有大量的中央git存儲庫,並使用分支來跟蹤各種項目的工作。 項目完成后,我們合並到母版並推送到原點。

當開始一個新項目時,我想列出該存儲庫上的任何其他當前工作,以提醒開發人員(例如,以便他們可以交流其發布計划)。 git branch --all --no-merged origin/master看起來很有希望,但顯然它只列出有提交的分支。 從概念上講,即使是新創建的“空”分支也說明了進行某些工作的意圖 ,因此也不應列出這些分支嗎?

我懷疑這可能與分支和分支頭之間的區別有關,並且當分支頭指向其起點時,沒有什么可合並的。 但是由於合並已明確記錄在歷史記錄中(對嗎?),是否有可能將“空”分支也標識為未合並? 能做到嗎?

一個明顯的解決方法是在每個新分支中強制執行虛擬初始提交,但我想盡可能避免這種情況。 而且,如果開發人員不願意,他們似乎不必推送未完成的更改(因此,我希望中央存儲庫中的大多數分支在項目完成之前都將保持空白)。

例:

# Alice creates and pushes branch1
git clone $REPO clone1
git checkout -b branch1
git push -u --all
# ...continues development in her local repository...

# Bob wants to know if anybody is working on $REPO
git clone $REPO clone2
git branch --all --no-merged origin/master
# no output - he doesn't realize Alice is working in the same repository

似乎我沒有想要的git內置支持,但是通過git管道,我得到了我想要的結果,這是受Git查找分支點啟發的

讓我知道這些假設是否正確...

  • 分支的頭部與origin/master節點的分支點相匹配的分支(即沒有提交)應為空分支,表明有工作意圖。
  • 分支與origin/master的最佳合並點匹配其頭部的分支已經完全合並,可以忽略。
  • 其他任何情況都應是具有未合並更改的分支。

為所有遠程分支打印類別的示例腳本; 如果Bob運行了它,它將告訴他refs/remotes/origin/branch1: new branch without any commits

#! /usr/bin/env bash

# check branches created from and merged to this branch
MASTER=refs/remotes/origin/master

# for each remote branch...
for BRANCH in $(git for-each-ref --format='%(refname)' refs/remotes/); do
    # ...except the $MASTER branch and the current HEAD
    [[ $BRANCH == $MASTER || $BRANCH =~ /HEAD$ ]] && continue

    # get the hash for the head of the branch
    BRANCH_HEAD=$(git show-ref --head --hash $BRANCH)

    # returns the first shared commit among $MASTER and $BRANCH commits
    BRANCH_POINT=$(fgrep -m 1 -f <(git rev-list --first-parent $BRANCH) \
                                 <(git rev-list --first-parent $MASTER))

    # find the best merge point
    BRANCH_MERGE=$(git merge-base $MASTER $BRANCH)

    # determine the type of branch
    if [[ $BRANCH_POINT == $BRANCH_HEAD ]]; then
        echo "$BRANCH: new branch without any commits"
    elif [[ $BRANCH_MERGE == $BRANCH_HEAD ]]; then
        echo "$BRANCH: fully merged into $MASTER"
    else
        echo "$BRANCH: branch with unmerged changes"
    fi
done

否,因為branch1中沒有未合並的更改。 因此,“-no-merged”不會列出分支。 愛麗絲提交並推送更改后,它將顯示出來。

恐怕我與Doug-W在一起。 --no-merged是指包含當前分支不包含的一個(或多個)提交的分支。 因為您是從master分支的,所以不進行后續提交,那么分支包含的所有提交也都在master內。

由於創建分支機構沒有創建分支機構的時間的概念,因此您將失去一個可能對您和您的公司將來很重要的指標。 如果僅使用一個簡單的“存根”文件創建分支后就只進行一次提交,則可以使用此存根提交的時間戳和第二個提交時間戳來了解項目在開始之前要停放多長時間。

這還具有在--no-merged命令中報告這些分支的額外好處。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM