简体   繁体   English

如何仅将最新合并的提交提交到git中的分支

[英]How to get only commits of the latest merge to a branch in git

So I figured out I can get the latest merge to master using git log master --merges -1 . 所以我弄清楚我可以使用git log master --merges -1将最新的合并掌握。 I would like to take this a step further and get only the latest commits from the latest merge to master. 我想更进一步,只从最新的合并中获取最新的提交到master。 How would one do this? 一个人怎么做?

For example let's say I have master , staging , feature1 and feature2 branches. 例如,假设我有masterstagingfeature1feature2分支。 I merge feature1 into staging and then into master . 我将feature1合并到staging ,然后合并到master Then I do the same with feature2 afterwards. 然后,我对feature2进行相同feature2 How do I get that happened between merging feature2 ? 我如何在合并feature2之间发生这种情况?

Have you tried the --children flag? 您是否尝试过--children标志?

git log master --children --merges -1

or you could try 或者你可以尝试

https://gist.github.com/kohsuke/7590246 https://gist.github.com/kohsuke/7590246

git log -1 --merges --pretty=format:"%H" gives you SHA of the the last merge commit. git log -1 --merges --pretty=format:"%H"为您提供最后一次合并提交的SHA。

You can use this SHA to filter the output of git rev-list --all --children and limit the results to commits whose parents are the given SHA1. 您可以使用此SHA过滤git rev-list --all --children的输出,并将结果限制为其父级为给定SHA1的提交。

COMMIT=`git log -1 --merges --pretty=format:"%H"`
git rev-list --all --children | grep "^${COMMIT}" | cut -f2 -d' '

According to git-rev-list documentation , 根据git-rev-list文档

--children Print also the children of the commit (in the form "commit child…"). --children还打印提交的子项(格式为“ commit child…”)。

So grep "^${COMMIT}" will ensure output will be lines that start with last merge commit. 因此, grep "^${COMMIT}"将确保输出为以最后一次合并提交开始的行。

After git log master --merges -1 , review the two parent commits of that merge. git log master --merges -1 ,检查该合并的两个父提交。 Then issue git log <parent1>..<parent2> --right-only --no-merges --format=format:%H to list the commits from the feature2 branch. 然后发出git log <parent1>..<parent2> --right-only --no-merges --format=format:%H列出来自feature2分支的提交。

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

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