How do I get the last merge from develop into master in Git?

谁都会走 提交于 2020-02-28 12:33:31

问题


In order to automate my CI, I need to get the info of the last merge executed from the develop branch into the master branch (or more generically, from a given source branch to a given destination branch). I tried with

git log --oneline --merges  master -20

but this get me a list of all the last 20 merges into master, without differentiating by source branch (leaving me with the cumbersome task to parse and infer the source branch from the comment). Is there a clean and robust way to filter by source branch directly from the command line ?

Note: I do not need for suggestions related to CI or branch-management best practices. We internally use the GitFlow workflow (https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow), so everything repository/CI-related is already in perfect order (methodologically speaking). I just need for a very specific answer to a very specific question, thanks !


回答1:


Is there a way to filter by source branch directly from the command line?

No. Branches in Git are just labels. Merges don't remember what branch they were merged to nor from, they only remember their parent commits and commit messages. Once merged both histories are equally part of the branch.

These are both different views of the same repository.

      < C <-- D <---- I [develop]
     /         \     /
A < B < E < F < G < H [master]

              <------ I [develop]
             /       /
A < B < C < D < G < H [master]
     \         /
      E <--- F

All commits except I are part of the master branch (ie. they can be reached from H). All commits are part of the develop branch (ie. they can be reached from I). Was G a merge from develop or from an unrelated branch? Topologically there is no way to tell.

Best you can do is hope try to deduce the information from the merge commit message and history. If your merge commit messages are consistent, you might be able to get away with something like this, but it is fragile.

git log --oneline --merges <destination> | grep "Merge branch '<source>'"



回答2:


I recommended create a special log, the next gist have a awesome log to view diferents branches, user and the commit time ago

https://gist.github.com/gollum23/bbb115977677b60eea97



来源:https://stackoverflow.com/questions/58388374/how-do-i-get-the-last-merge-from-develop-into-master-in-git

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!