Commit history on remote repository
Asked Answered
P

10

289

I am trying to access a branch's commit history on a remote repository. I had a look at the doc but could not find any substantial information on how to access a remote repo's commit history using my local git client.

Posthorse answered 18/12, 2012 at 21:43 Comment(1)
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all I don't know where I get this, but It works for meBrendabrendan
I
341
git log remotename/branchname

Will display the log of a given remote branch in that repository, but only the logs that you have "fetched" from their repository to your personal "copy" of the remote repository.

Remember that your clone of the repository will update its state of any remote branches only by doing git fetch. You can't connect directly to the server to check the log there, what you do is download the state of the server with git fetch and then locally see the log of the remote branches.

Perhaps another useful command could be:

git log HEAD..remote/branch

which will show you the commits that are in the remote branch, but not in your current branch (HEAD).

Ieyasu answered 19/12, 2012 at 1:18 Comment(7)
"You can't connect directly to the server to check the log there" - that was the issue I was havingInroad
I'm only getting local pulled changes... note the remote ones, even doing fetch before.Footbridge
When doing a git fetch you need to use --all to fetch from remotes.Madelina
That's too bad, so I have to clone 2GB worth of objects just to look through the commit logs?Clayson
I just verified this by running the command on a repo I knew I was locally behind on; the first entry returned reflected the latest commit remotelyCabral
Hi @Clayson you can mitigate pain by managing the amount of data fetched with a shallow clone (see --depth in git-scm.com/docs/git-clone), then manage fetches with (see "shallow" in git-scm.com/docs/git-fetch).Emulsify
This answer was helpful, and then https://mcmap.net/q/107384/-commit-history-on-remote-repository and https://mcmap.net/q/107384/-commit-history-on-remote-repository added more helpful information too.Synod
P
81

NB. "origin" below use to represent the upstream of a cloned repository, replace "origin" with a descriptive name for the remote repo. "remote reference" can use the same format used in clone command.

git remote add origin <remote reference>
git fetch
git log origin/master
Psychographer answered 18/12, 2012 at 21:56 Comment(8)
what is remote reference here?Posthorse
@Posthorse The remote repository Git URL, e.g. git://git.somedomain.tld/some/repoExtended
Don't you need to specify <refspec> when fetching (or use fetch --all) if you're not tracking any branch on the remote?Extended
@all - lets ay I want to fetch from git URL:git.qrepo.com from branch "master" and project "vendor/diag" ,what would be the commands?Posthorse
What do you mean with "project vendor/diag"? Is that a folder inside the repository? Another branch?Gentle
@LopSae - a repository has multiple projects and branches..vendor/diag is another project,I still cant get these commands to workPosthorse
A repository can have multiple branches, but "project" is not a term related to git, from there the confusion to what a "project" means in this case. Still, what would that have to do with the question?Gentle
I don't believe its possible to do this in GIT. You must clone that remote repository before you can issue a git log against it.Preoccupy
S
52

I'm not sure when filtering was added but it's a way to exclude the object blobs if you only want to fetch the history/ref-logs:

git clone --filter=blob:none --no-checkout --single-branch --branch master git://some.repo.git .
git log
Sharl answered 31/3, 2020 at 14:18 Comment(3)
This is perfect. Given the other answers, it would be awesome if this were able to stand out next to the provided answer.Uprising
You deserve 20 stars for this....Aluminothermy
Also, since you are checking out a specific branch you can also add --filter=tree:0 to exclude other branch trees. Adding tree:0 was 75% smaller than without.Aluminothermy
P
20

A fast way of doing this is to clone using the --bare keyword and then check the log:

git clone --bare git@giturl tmpdir
cd tmpdir
git log branch
Pilewort answered 22/12, 2015 at 11:4 Comment(0)
G
16

This is what worked for me:

git fetch --all 
git log production/master

Note that this fetches from ALL remotes, i.e. potentially you "have to clone 2GB worth of objects just to look through the commit logs".

Guanabana answered 17/2, 2018 at 8:53 Comment(0)
P
13

I don't believe this is possible. I believe you have to clone that remote repo locally and perform git fetch on it before you can issue a git log against it.

Preoccupy answered 26/1, 2015 at 19:22 Comment(2)
imagine you already clone the repo to local and make some changes . . then you want to check if anyone has committed to the remote repoDewayne
If you change this answer to "It is not possible" then this is the best answer. There is no way to access a remote repo's commit history using a remote git client.Emulsify
M
13

You can only view the log on a local repository, however that can include the fetched branches of all remotes you have set-up.

So, if you clone a repo...

git clone git@gitserver:folder/repo.git

This will default to origin/master.

You can add a remote to this repo, other than origin let's add production. From within the local clone folder:

git remote add production git@production-server:folder/repo.git

If we ever want to see the log of production we will need to do:

git fetch --all 

This fetches from ALL remotes (default fetch without --all would fetch just from origin)

After fetching we can look at the log on the production remote, you'll have to specify the branch too.

git log production/master

All options will work as they do with log on local branches.

Madelina answered 25/7, 2015 at 9:57 Comment(0)
A
3

git isn't a centralized scm like svn so you have two options:

It may be annoying to implement for many different platforms (GitHub, GitLab, BitBucket, SourceForge, Launchpad, Gogs, ...) but fetching data is pretty slow (we talk about seconds) - no solution is perfect.


An example with fetching into a temporary directory:

git clone https://github.com/rust-lang/rust.git -b master --depth 3 --bare --filter=blob:none -q .
git log -n 3 --no-decorate --format=oneline

Alternatively:

git init --bare -q
git remote add -t master origin https://github.com/rust-lang/rust.git
git fetch --depth 3 --filter=blob:none -q
git log -n 3 --no-decorate --format=oneline origin/master

Both are optimized for performance by restricting to exactly 3 commits of one branch into a minimal local copy without file contents and preventing console outputs. Though opening a connection and calculating deltas during fetch takes some time.


An example with GitHub:

GET https://api.github.com/repos/rust-lang/rust/commits?sha=master&per_page=3

An example with GitLab:

GET https://gitlab.com/api/v4/projects/inkscape%2Finkscape/repository/commits?ref_name=master&per_page=3

Both are really fast but have different interfaces (like every platform).


Disclaimer: Rust and Inkscape were chosen because of their size and safety to stay, no advertisement

Automaton answered 31/10, 2020 at 16:49 Comment(0)
P
0

Here's a bash function that makes it easy to view the logs on a remote. It takes two optional arguments. The first one is the branch, it defaults to master. The second one is the remote, it defaults to staging.

git_log_remote() {
  branch=${1:-master}
  remote=${2:-staging}
  
  git fetch $remote
  git checkout $remote/$branch
  git log
  git checkout -
}

examples:

 $ git_log_remote
 $ git_log_remote development origin
Pollen answered 9/6, 2020 at 18:21 Comment(2)
Why are you doing git checkout $remote/branch ; git log ; git checkout -. Wouldn't just git log $remote/branch work here?Peaceable
@MichaelFirth I just checked and indeed it would. Knowing that really make the helper function obsolete. Thanks!Pollen
P
0

I was looking for remote branches that contained a particular commit

here's a quick script you can use as an example

spark 
✦ ❯ cat run.sh
for b in $(git branch -r)
do

    hasKryoCommit=$(git log "$b" | grep 3e033035a3c0b7d46c2ae18d0d322d4af3808711)
    if test -n "$hasKryoCommit"
    then
        echo "$b"
    fi
done

spark 
✦ ❯ bash run.sh
origin/HEAD
fatal: unrecognized argument: ->
origin/master
origin/branch-2.4
origin/branch-3.0
origin/branch-3.1
origin/branch-3.2
origin/master
Pertinacious answered 7/3, 2022 at 1:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.