List Git commit SHAs from a specific branch without cloning the repository

时间:2019-04-08 14:02:05

标签: git github gitlab

Is there a way to get all the commit IDs for a particular branch without cloning the repository or using the API's?

I'm looking for something like this. Unfortunately the below command works only within the repository (i.e., git directory). I want to able to do it without cloning the repo.

git rev-list --remotes=*master 

For example, the below command brings all the branches and it's last commit ID (Note: the command works without having to clone the repo.)

git ls-remote -h http://user:password@example.gitlab.com/ProjectA/example.git 

Sample output:

82cd0dcc9d1005b44bdc799034b706f9ad2b1e0e    refs/heads/master
afacc961fedf49a84c09ab91e67633b02921dd07    refs/heads/projects/myproject
b6d954ec86750dcfd35c1c3fba4f40449abeb6ed    refs/heads/releases/production
e891a0b29847d0d7dfc5bc7e5ad45f718918f67f    refs/heads/releases/ready_for_prod
7b0282004a6f72c5803ddf19172c16a0b3124038    refs/heads/releases/test

3 个答案:

答案 0 :(得分:2)

使用常规的Git命令是不可能的,但是您已经用标记了您的问题,这两个API都可以让您做到:

  • GitHubGET /repos/:owner/:repo/commits并提供参数sha,其中包含要列出其提交的分支的名称
  • GitLabGET /projects/:id/repository/commits并提供参数ref_name,其中包含要列出其提交的分支的名称

您可能需要使用GitLab企业版才能使用其API。 (在GitLab.com上托管的版本应支持它。)

答案 1 :(得分:0)

是的,要与存储库进行交互,您需要先对其进行克隆。

克隆后,运行:

git rev-list branch/name

答案 2 :(得分:0)

要获得您想要的输出,UserControl的格式会更容易:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:penny_project_1/src/blocs/dataBloc.dart';

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          StreamBuilder<String>(
              stream: bloc.getTextStream,
              builder: (context, snapshot) {
                return TextField(
                  onChanged: bloc.addString,
                  decoration: InputDecoration.collapsed(
                    hintText: 'Category@Value',
                  ),
                );
              }),
          RaisedButton(
            onPressed: () {},
            child: Icon(Icons.add),
          )
        ],
      ),
    );
  }
}