[英]How can I compare two Git branches and only list the new commits in the feature/topic (second) branch
[英]How do I list git branches with commits only to a specific directory?
我們的團隊致力於大型 git 存儲庫。
最近我們決定將一個子目錄(命名為 framework)導出到一個單獨的 repo,並刪除所有包含只提交到該子目錄的分支。
我怎樣才能列出這樣的分支?
我修改了這個建議以獲得:
for branch in `git for-each-ref --format="%(refname)" refs/remotes/origin `; do
git ls-tree -r --name-only $branch | grep -q "framework/" && echo $branch
done
但是,此命令也會返回帶有提交到其他子目錄的分支。
我試過擴展這個片段:
for branch in `git for-each-ref --format="%(refname)" refs/remotes/origin `; do
if git ls-tree -r --name-only $branch | grep -q "framework/" ; then
if ! git ls-tree -r --name-only $branch | grep -vq "framework/" ; then
echo $branch
fi
fi
done
但是,此命令不打印任何內容。
由於framework/
是您的存儲庫的一部分,所有分支都包含一個名為framework/
的目錄,因此您的git ls-tree
命令將始終列出一些內容。
如果你有一個參考分支(比如master
或develop
),你可以檢查一個分支是否修改了這個目錄,因為它是從那個分支派生出來的:
# will give view an understandable view of what commits are part of this branch :
git log --graph --oneline master..$branch -- framework/
# will give you an int as output (easier to use in a script) :
git rev-list --count master..$branch -- framework/
如果要排除多個“參考分支”,可以使用a..b
的替代語法:
# count commits from $branch that modified 'framework/' since it forked
# either from master or from develop :
git rev-list --count ^master ^develop $branch -- framework/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.