Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find last merge in git?

Tags:

git

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.

like image 212
Hans Avatar asked Feb 04 '11 14:02

Hans


People also ask

How can I see last merge?

Try simply git whatchanged master.. staging to see what changed on staging since you last merged from staging to master.

Does git merge keep history?

Merging. When you run git merge , your HEAD branch will generate a new commit, preserving the ancestry of each commit history.

How do I find a merge commit?

To see the merge commit's message and other details, use git show-merge with the same arguments.

How do I restore my last merge?

You can use the Git reset command to undo a merge. Firstly, you need to check for the commit hash (or id) so you can use it to go back to the previous commit. To check for the hash, run git log or git reflog . git reflog is a better option because things are more readable with it.

How can I see all of my Git merges?

git log has a tool you can use to visualize all of this merging, --graph. The output looks like this: This graph shows not only the commits (as asterisks *) but also their “parent” commits. Most commits—“ordinary” commits — have only one parent: the last commit of the branch you were on when the commit was created.

How do I merge two branches in Git?

A git merge operation is performed by running the command “git merge <name of the branch to be merged (in our case it is “dev”)>”. When we perform merging, git always merges with the current branch from where we are performing the operation (in our case it is “main”). By this, the branch being merged is not affected.

How do I find the last commit in git log?

For instance, if you wanted to find the last commit that added or removed a reference to a specific function, you could call: The last really useful option to pass to git log as a filter is a path. If you specify a directory or file name, you can limit the log output to commits that introduced a change to those files.

How to go back to the last commit before the merge?

When you get the hash of the commit you want to get back to, run git reset --hard commit-before-the-merge: You should see some things get removed from your code editor when you run the command. If you are not sure of the hash of the last commit, you can run git reset --hard HEAD~1 to go back to the commit before the merge:


2 Answers

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.

like image 66
Razzi Abuissa Avatar answered Oct 18 '22 19:10

Razzi Abuissa


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.

like image 37
alex Avatar answered Oct 18 '22 20:10

alex