![](/img/trans.png)
[英]How can I compare two Git branches and only list the new commits in the feature/topic (second) branch
[英]Compare two git branches without intermediate commits (i.e. only commits that are accessible from the branches)
讓我們假設我在同一個提交上有一個 git master 分支和兩個功能分支(功能 1,功能 2):
A1 -- A2 (master)
\
B1 -- B2 (feature1, feature2)
現在我使用 master 的更改重新設置 feature2 分支:
A1 -- A2 -- A3 -- A4 -- A5 -- A6 (master)
\ \
B1 -- B2 (feature1) B1 -- B2 (feature2)
並可能對 feature2 進行一些重構 ( B2'
) 和其他更改 ( B3
):
A1 -- A2 -- A3 -- A4 -- A5 -- A6 (master)
\ \
B1 -- B2 (feature1) B1 -- B2' -- B3 (feature2)
我想要做的是僅從兩個功能分支(而不是主分支)的內容中獲取差異,以便查看功能分支上而不是主分支上重構和更改的內容。 即我想獲得B1 -- B2
和B1 -- B2' -- B3
之間的差異。 我不關心在此期間推送給 master 的更改。 有 cmd 命令嗎?
據我所知, git diff
命令只比較顯式內容,沒有將多個補丁組合在一起的內置方法。
您可以做的是創建一個臨時分支,並創建您希望比較的內容:
# for example :
git checkout feature1
git checkout -b compare1
git rebase A6
git diff feature2
構建內容的另一種方法可能是應用補丁A2 A6
上的頂部feature1
,或者在頂部的反向補丁feature2
:
git checkout feature1
git diff A2 A6 | git apply
# or
git checkout feature2
git diff A6 A2 | git apply
# after inspecting the diff : discard these changes
git checkout .
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.