3

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:password@bitbucket.org/panchalajay/master.git -b branchName --single-branch

ajay panchal
  • 145
  • 1
  • 11

2 Answers2

1

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Here is the link to get as refs , here they get the details but i want the details of particular branch [link -->https://gist.github.com/l15n/3103708] – ajay panchal Sep 03 '16 at 07:41
  • @ajaypanchal your gist is about Git command which run in a *local* repo. So the question is: do you have cloned the BitBucket repo, or do you want those information *without* cloning the repo (which is what my answer is about) – VonC Sep 03 '16 at 08:02
  • Actually i want it without cloning , but if u have its ans after cloning you can suggest me. @VonC – ajay panchal Sep 03 '16 at 08:08
0

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.