如何查看一个分支的更改是否已经在另一个分支中完成?
How to see if changes from a branch are already done in another one?
我想知道我对 BranchA 的所有代码更改是否已经应用到 BranchB,无论提交 ID 是否相同或 BranchB 是否有大量额外更改
这可能吗?
示例:
Branch A : Commit 111... -> Add line 23
Commit 222... -> Add line 24
Branch B: Commit 333... -> Add line 23
Commit 444... -> Add line 24
Commit 555... -> Remove line 24
Commit 666... -> Add line 25
Commit 777... -> Add line 26
What I basically would like to know is whether the two changes from Branch A are already applied by other commits on Branch B.
In this case, the output I would like to see is:
- Add line 24
Why? Because this is the only change from Branch A not matching latest state of Branch B. I want to discard extra staff exclusive in Branch B (commits 666 and 777). I also want to consider latest state of Branch B, so even Branch B added at some point line 24, the latest state is removed, so that is the only differing change in regards to Branch A
在使用比较和差异时,我通常会看到 B 分支的所有额外员工,我对此不感兴趣,因为我只想知道分支 A 上下文中的差异
如果您合并所有更改,可以使用 git log BranchB..BranchA
(即 "give me all commits that are in A and not in B")来完成。如果此 returns 没有,则应用所有 A 更改。
如果您使用变基或以完全不同的方式实施更改,则无法检查这一点,因为您的更改可能稍后被更改或完全覆盖。您可以尝试grep一些相关行或构建软件,看看它是否具有您想要的功能,但没有通用的方法。
你也可以这样做:
git branch --contains BranchA
列出具有所有 BranchA 提交的所有分支。如果您在列表中找到您的 BranchB,那您就很好了。
如果有很多分支,通过管道连接到 grep :
git branch --contains BranchA | grep BranchB
评论后编辑:
如果您必须检测更改,而不管它们属于哪个提交,例如,当您重新设置或挑选一些工作时,如 ,您可以这样做:
git log --cherry BranchB..BranchA
但话又说回来,虽然 检测 更改将发生在代码级别,但无论提交哈希如何,默认情况下输出本身都会作为提交给出。要查看这些提交中的实际代码更改,您可以使用 -p
选项,并可能将其存储在文件中:
git log -p --cherry BranchB..BranchA > output.txt
我想知道我对 BranchA 的所有代码更改是否已经应用到 BranchB,无论提交 ID 是否相同或 BranchB 是否有大量额外更改
这可能吗?
示例:
Branch A : Commit 111... -> Add line 23
Commit 222... -> Add line 24
Branch B: Commit 333... -> Add line 23
Commit 444... -> Add line 24
Commit 555... -> Remove line 24
Commit 666... -> Add line 25
Commit 777... -> Add line 26
What I basically would like to know is whether the two changes from Branch A are already applied by other commits on Branch B.
In this case, the output I would like to see is:
- Add line 24
Why? Because this is the only change from Branch A not matching latest state of Branch B. I want to discard extra staff exclusive in Branch B (commits 666 and 777). I also want to consider latest state of Branch B, so even Branch B added at some point line 24, the latest state is removed, so that is the only differing change in regards to Branch A
在使用比较和差异时,我通常会看到 B 分支的所有额外员工,我对此不感兴趣,因为我只想知道分支 A 上下文中的差异
如果您合并所有更改,可以使用 git log BranchB..BranchA
(即 "give me all commits that are in A and not in B")来完成。如果此 returns 没有,则应用所有 A 更改。
如果您使用变基或以完全不同的方式实施更改,则无法检查这一点,因为您的更改可能稍后被更改或完全覆盖。您可以尝试grep一些相关行或构建软件,看看它是否具有您想要的功能,但没有通用的方法。
你也可以这样做:
git branch --contains BranchA
列出具有所有 BranchA 提交的所有分支。如果您在列表中找到您的 BranchB,那您就很好了。
如果有很多分支,通过管道连接到 grep :
git branch --contains BranchA | grep BranchB
评论后编辑:
如果您必须检测更改,而不管它们属于哪个提交,例如,当您重新设置或挑选一些工作时,如
git log --cherry BranchB..BranchA
但话又说回来,虽然 检测 更改将发生在代码级别,但无论提交哈希如何,默认情况下输出本身都会作为提交给出。要查看这些提交中的实际代码更改,您可以使用 -p
选项,并可能将其存储在文件中:
git log -p --cherry BranchB..BranchA > output.txt