ajay panchal
ajay panchal

Reputation: 155

How to find last committed user name and details of remote branch

I have a branch in bitbucket , now i want to find the details (with user name of last commit of this branch) of last commit in single git command(remote branch). I tried this command but it say that Not a git branch.

git log https://userName:[email protected]/panchalajay/master.git -b branchName --single-branch

Upvotes: 3

Views: 867

Answers (2)

Actually you can not do this in just one command and without cloning it or going in Bitbucket ui, because you have to update the references of the remote.
That said, it is really simple :

git fetch
git log origin/yourBranch -10

The fetch will not merge the remote commits in your local branch instead of the pull.
You can also make an alias if you want.

Upvotes: 0

VonC
VonC

Reputation: 1323793

Without cloning the repo, only git ls-remote would contact the remote repo to get back data (ie, the branches names and SHA1 and tags).

git ls-remote would not bring back any other information like authorship.
For that, you might have to use the BitBucket API like the commit/revision one.
That would bring back all the information you need about a specific commit.

So:

  • either use git ls-remote to get the remote branch SHA1, plus the BitBucket API
  • or use only BitBucket API calls in order to query the remote repo. (Like refs/branches to get those same remote branches names and SHA1)

With a repository already cloned, my old answer (which is the basis for this gist) is enough.
You can add a filter to print the data only for a specific branch.

Make a bash script called git-infob (no extension, works even on Windows) with:

#!/bin/bash
bname=$1
branches=$(git branch -r | grep -v HEAD)
for branch in ${branches}; do
    branch_name=$(echo -n $branch | sed -e "s/origin\///g")
    # echo ii ${branch_name} ${bname}
    if [ "${bname}" == "${branch_name}" ]; then
        git log -1 --format="%ai %ar by %an" $branch
    fi
done

Put that script anywhere in your $PATH/%PATH%, and call git infob master.

Upvotes: 1

Related Questions