[英]Find files that changed specifically in a branch
I have a git repository in which I usually work on two branches, a public
branch, and a private
branch, the latter following closely the public branch, but with a few extra additions. 我有一个git存储库,我通常在其中工作两个分支,一个
public
分支和一个private
分支,后者紧随公共分支,但还有一些额外的添加。
Is there a way to find the changes since a given commit that are specific to the private branch ? 自给定提交以来,是否存在找到专用于私有分支的更改的方法?
The closest I can think of is to do something on the lines of: 我能想到的最接近的方法是:
git diff base..public > pub.diff
git diff base..private > private.diff
interdiff pub.diff private.diff
This works, but it's not that robust, and I'm sure it's possible to do that with git
in a better way. 这行得通,但并不是那么健壮,而且我确信可以用更好的方式用
git
做到这一点。
This is essentially how the branches look (with many more merges): 本质上是分支的外观(具有更多合并):
...A---B---C---D---E---F---G---H public
\ \ \
A'--I---J---D'--K---L---G'--M private
For instance, let's assume that base
above is D
in this scheme. 例如,假设在此方案中,上面的
base
为D
Just running 刚跑步
git diff D'..M
will also give me the results of the merge commit G'
. 还会给我合并提交
G'
的结果。 I'd like to avoid that, and have something robust across any numbers of merges. 我想避免这种情况,并且在任何数量的合并中都具有强大的功能。
is about comparing two endpoints, not ranges
关于比较两个端点,而不是范围
This might not be possible ( git diff
will not detect were those changes came from). 这可能是不可能的(
git diff
将无法检测到这些更改来自何处)。
You could try using 您可以尝试使用
$ git log -p --no-merges --first-parent D'..M
-p
gives you a diff (patch) for the commits listed -p
给您列出的提交的差异(补丁) --no-merges
will exclude merges from the list --no-merges
将排除列表中的合并 --first-parent
will only follow the first parent (the one you merged into eg private
) --first-parent
将仅跟随第一个父母(您合并为例如private
父母) D'..M
as explained in git revisision will D'..M
将
Include commits that are reachable from
<rev2>
but exclude those that are reachable from<rev1>
包括从可到达的提交
<rev2>
但排除那些可达从<rev1>
A different approach would be to follow @torek's suggestion and create a temporary branch, cherry-pick
all the commits onto it and then look at the diffs from this branch. 一种不同的方法是遵循@torek的建议并创建一个临时分支,
cherry-pick
所有提交cherry-pick
,然后查看该分支的差异。
Because AFAIK git cherry-pick
is not able to skip commits when specifying commit ranges you would first need to get a list of commits for cherry-picking (Here Option A is useful) 由于在指定提交范围时AFAIK
git cherry-pick
无法跳过提交,因此您首先需要获取用于樱桃选择的提交列表 (在这里, 选项A很有用)
$ git log --no-merges --first-parent D'..M --pretty=format:%H
--pretty=format:%H
will print all the commit hashes in long form --pretty=format:%H
将以长格式打印所有提交哈希 Create the temporal branch (which needs to have the correct starting point) 创建时间分支(需要具有正确的起点)
$ git checkout -b temp D'
And then cherry-pick those commits manually or try using this command (exchanged for a better command suggested by @torek) 然后手动选择那些提交或尝试使用此命令(已替换为@torek建议的更好的命令)
$ git cherry-pick $(git rev-list --reverse --topo-order --no-merges --first-parent D'..M)
--reverse
is used to reverse the order of commits printed (oldest to newest instead of the other way around) --reverse
用于反转打印的提交顺序(从最旧到最新,而不是相反) --topo-order
this will avoid problems with commits that have weird or wrong timestamps --topo-order
这样可以避免时间戳奇怪或错误的提交问题 --no-merges
skip merge commits --no-merges
跳过合并提交 --first-parent
follow the mainline branch (eg the branch the merges were merged into ) --first-parent
跟随主线分支(例如合并到的分支) This approach might fail if commits are based on changes which were merged in 如果提交基于合并到其中的更改,则此方法可能会失败
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.