Reputation: 321
Git is such a well written piece of software, that you can spend a long time using it without really understanding whats going on.
I'm trying to get the name of the branch which was merged with the master branch most recently, and I don't seem to be getting anywhere with git log, git show etc.
Github has the branch name history when I look at the commits to master, but I'm wondering if this is something that github is keeping track of additionally and not something I can access by git. Any help would be much appreciated!
Upvotes: 3
Views: 4781
Reputation: 641
if you create pull requests (black circle) and merge branch in github, you can find information of a merge commit by clicking in 22 Closed
(red circle)
Upvotes: 0
Reputation: 2499
As @torek mentioned in the comment, you can use a message within the merge commit itself.
#!/bin/bash
commit_subject=$(git log -1 --pretty=format:%s)
echo Commit subject: $commit_subject
regex='Merge pull request #[0-9]+ from .+/(.+)$'
[[ $commit_subject =~ $regex ]]
branch_name=${BASH_REMATCH[1]}
echo Merged branch: $branch_name
Example output:
Commit subject: Merge pull request #2574 from RepoName/BranchName
Merged branch: BranchName
Upvotes: 0
Reputation: 1326892
As commented, this information is not recorded.
You might consider a post-merge
hook, like this one, which would:
git reflog
)git notes add
in order to add the the current merge commit the information you want.That is a local hook though, that would need to be installed on every cloned repository. If you are alone working on the repository, that would work.
Upvotes: 2