How to find last merge in git?

后端 未结 7 1416
野的像风
野的像风 2020-12-29 04:31

For a web site, I have master and staging, I have worked on staging for about 10 days. How do I tell for sure what has changed since my last merge, or when that merge was? M

相关标签:
7条回答
  • 2020-12-29 04:47

    Try this, it will select the last branch where the commit message starts with "Merge":

    git show :/^Merge
    

    Here's a website with a few git tips that might help you out.

    0 讨论(0)
  • 2020-12-29 04:47
    git log --merges -n 1
    

    works well. From man git-log:

       --merges
           Print only merge commits. This is exactly the same as --min-parents=2.
    

    Here's an example using --pretty=format:"%H" to get just the SHA.

    $ git log --pretty=format:"%H" --merges -n 1
    f32e1f13eef7d5843e8063b8709d01af6dcd5dbf
    

    Credit goes to Jefromi for their comment on another answer.

    0 讨论(0)
  • 2020-12-29 04:47

    Why not simply diff your staging branch against master? That will show you the actual differences in each of your files, and not only those unmerged stuff. Also things you may have dropped when merging from staging to master in the past.

    try git diff master..staging or git diff master...staging to see the diff from their common ancestor to 'staging'.

    0 讨论(0)
  • 2020-12-29 04:54

    It looks like you don't really want to know what is changed since last merge, but what have I on branch staging that is not yet on branch master? (or the other way around). If so, look at the command git cherry.

    Though I must confess I never used this command because of the output format, which is not really helpful. Maybe there is a way to feed this output to git log/git show or such.


    Edit: As I understand, you don't need a tag to use git whatchanged. Try simply git whatchanged master..staging to see what changed on staging since you last merged from staging to master.

    0 讨论(0)
  • 2020-12-29 04:56

    An alternative which does not rely on the content of the commit message:

    $ git rev-list --min-parents=2 --max-count=1 HEAD
    9c6e6d6b6b9bd293335700e34e05217ae8e7a7e8
    

    --min-parents=2 selects only commits which are merges, --max-count=1 only shows the first commit when going back in history. If the specified commit (HEAD) does not have any merge commits in its history, the output will be empty.

    0 讨论(0)
  • 2020-12-29 05:00

    Take the latest merge and give branch name which merged to current branch

    MC=git log --merges -n 1 | grep request; BB=${MC##*:}; B=${BB%% }; SUBBRANCH=${B##/} echo $MC

    0 讨论(0)
提交回复
热议问题