简体   繁体   English

从Bitbucket / Stash查找“拉取请求”的差异

[英]Find the diff of a “pull request” from Bitbucket / Stash

(Stash = locally hosted Bitbucket.) (存储=本地托管的Bitbucket。)

I have the typical git workflow: create a branch, work on it, push it to Stash periodically, rebase off master periodically, merge to master via Stash. 我有典型的git的工作流程:创建一个分支,它的工作,将其推到定期藏匿,重订掉master定期,合并master通过藏匿。

The result is a pull request in Stash that contains just the right commits. 结果是在Stash中的拉取请求仅包含正确的提交。

  • Is there a way to find these commits using git on command line? 有没有办法在命令行上使用git查找这些提交? git log does contain them, but git reflog <my-feature-branch> shows only some of them. git log确实包含它们,但是git reflog <my-feature-branch>仅显示其中一些。
  • Having found these commits, how do I produce a diff of my PR? 找到这些提交后,如何产生PR的差异? The last commit is obvious, but I can't find the right initial point. 最后一次提交是显而易见的,但是我找不到正确的起点。

Update - from comments, you say you're doing analysis after the branch has been merged and after some rebases. 更新 -从注释中可以看出,分支合并后和进行一些基础调整后,您正在进行分析。 I wouldn't normally assume that matters, because: 我通常不会认为这很重要,因为:

1) Either you have my_feature_branch sitting on the commit before the merge, or you don't. 1)要么在合并之前让my_feature_branch坐在提交上,要么不这样做。 You've mentioned being able to see the commits with git log , so I assume finding the branch tip isn't a problem. 您已经提到能够使用git log查看提交,因此我认为找到分支提示不是问题。

2) Rebasing things onto master generally won't change anything with respect to the meaning of master..my_feature_branch or master...my_feature_branch (in their respective contexts). 2)在master..my_feature_branchmaster...my_feature_branch (在它们各自的上下文中)的意义上,将事物放到master上通常不会改变任何东西。

But since I assume you're not the sort of person who reads the first sentence of an answer and then writes a defensive comment without having tried the advice the answer gave you, that suggests you may have done a rebase that would change the relationship between the branches - in which case the nature of that rebase should be spelled out in the question. 但是由于我认为您不是那种先读答案的第一句话然后写防御性评论而不尝试答案给您的建议的人,这表明您可能已经进行了重新定位, 从而改变了分支机构-在这种情况下,应该在问题中阐明该基准的性质。

You say you understand that git doesn't know anything of pull requests, yet you dismiss comparisons based on things git does know about and continue to ask if there's a way to have git tell you about the pull request... No, there isn't. 您说您了解git不知道任何请求请求,但是您根据git知道的事情关闭了比较,并继续询问是否有git可以告诉您有关请求请求的方法...不,没有没错 What you want is the history of the commit at which my_feature_branch pointed when the PR was created, less any history of the ocmmit at which master pointed at the same time. 您想要的是创建PR时my_feature_branch指向的提交历史记录,而不是master指向的ocmmit的历史记录。 You may have done operations that complicate that, or you may only think that you have. 您可能已经完成了使事情复杂化的操作,或者您可能只是认为自己已经拥有了。

If the commit that master pointed to at that time, is reachable (by parent pointers) from master now; 如果master当时指向的提交,现在可以从master到达(通过父指针); and if you have any ref pointing to (or the SHA ID of) the commit my_feature_branch pointed to at that time, then the notation I already recommended will work. 如果您当时有任何引用指向(或指向其SHA ID)提交my_feature_branch ,那么我已经推荐的符号将起作用。

Even if my_feature_branch was rebased, so long as its new base is still in the history of master and the rebase didn't drop or edit commits, the same notation would still work using the rewritten commit corresponding to the old my_feature_branch tip. 即使对my_feature_branch进行了重新设置,只要其新基础仍在master的历史记录中,并且该重新设置没有删除或编辑提交,使用与旧的my_feature_branch技巧相对应的重写提交,相同的表示法仍然可以使用。

If you've rewritten my_feature_branch in some other way (and didn't keep track of the original commit), then your best bet would be to find the tip commit in the reflog and then use regular git log and git diff (as outlined below) using that commit's SHA instead of the branch ref name. 如果您以其他方式重写了my_feature_branch (并且未跟踪原始提交),那么最好的选择是在reflog中找到提示提交,然后使用常规git loggit diff (如下所述) )使用提交的SHA而不是分支引用名称。


Note that a pull request is not a "core git" concept; 请注意,拉取请求不是“ core git”概念。 it is peculiar to the service in which the repo is hosted. 它是托管回购协议的服务所特有的。 What you're really examining is a branch, for which you have issued a pull request. 您真正要检查的是分支,您已经为其发出了拉取请求。

I don't understand your first question. 我不明白你的第一个问题。 As you have correctly identified, git log shows the history of the branch. 如已正确识别, git log显示分支的历史记录。 The reflog is something else (a local history of where the ref has pointed in this particular clone) and isn't what you want. 引用日志是其他内容(引用在此特定克隆中指向的本地历史记录),而不是您想要的。 I guess the trouble with git log is, how to make it only show the commits that are not yet in master? 我想git log的麻烦在于,如何使其显示尚未在master中的提交? You can do this by 你可以这样做

git log master..my_feature_branch

(Note: two dots in this case.) So if you have (注意:在这种情况下为两个点。)因此,如果有

x --- x --- x --- x <--(master)
       \
        A --- B --- C <--(my_feature_branch)

this log output will list A , B , and C . 此日志输出将列出ABC

As for how to do the diff, it's similar but a little different: 至于如何做差异,它是相似的,但有些不同:

git diff master...my_feature_branch

(Note: 3 dots this time.) (注意:这次是3个点。)

This automatically finds the "merge base" for master and my_feature_branch and diffs my_feature_branch against the base. 此自动查找“合并基础”用于mastermy_feature_branch和diff文件my_feature_branch靠基部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM