Reputation: 3523
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? Most of the merges I have done end up being FFs so I can't log them like git merge branch -m 'merging staging'
(git reports it ignored -m). I usually merge master into staging for testing before merging staging into master for more testing and deployment.
I could tag each one but I'm worried about the clutter of doing that for merges. What I'd like to know is "roughly, what changed since my last merge of staging into master?" Then I could make sure I spent extra time investigating those changes in the final examination. Sometimes co-workers make changes I hadn't noticed until this stage.
I suppose since staging->into->master merges are rare, I could tag them and then do a "git whatchanged tag" but I'm hoping there is a non-tag way to do it. Thanks.
Upvotes: 34
Views: 35629
Reputation: 3720
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.
Upvotes: 22
Reputation: 11
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
Upvotes: 0
Reputation: 4092
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.
Upvotes: 43
Reputation: 2194
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'.
Upvotes: 0
Reputation: 9922
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.
Upvotes: 13
Reputation: 3523
Looks like this is my best bet:
I edited ~/.gitconfig, adding:
[branch "master"]
mergeoptions = --no-ff
Then if I'm on master and I merge in a branch, it shows it as a full merge. Having that as a config option for just "master" shows how awesome git is, so I can still FF merges within branches, where I'm likely to have a lot of short-lived topic branches, and I don't have to remember to specify --no-ff when merging on master. Beautiful.
I use this alias for viewing logs:
k = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr, %cd) %C(bold blue)<%an>%Creset' --abbrev-commit
> git k (similar to the gui gitk, but stays in the terminal)
When I view logs that way, it paints a nice picture of the branching. If I want to find the last one, I can do
> git show :/"Merge branch 'staging'"
Thanks for the help.
EDIT: As @jefromi noted in the comments to the first answer, this is probably a better technique git log --merges -n 1
Upvotes: 3
Reputation: 74750
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.
Upvotes: 1