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.
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
).
git fetch
you need to use --all
to fetch from remotes. –
Madelina 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
git://git.somedomain.tld/some/repo
–
Extended <refspec>
when fetching (or use fetch --all
) if you're not tracking any branch on the remote? –
Extended 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
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
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".
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.
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.
git
isn't a centralized scm like svn
so you have two options:
- Use the web interface of target platforms (f.e. GitHub REST API or GitLab REST API)
- Download the repository and display logs locally
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
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
git checkout $remote/branch ; git log ; git checkout -
. Wouldn't just git log $remote/branch
work here? –
Peaceable 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
© 2022 - 2024 — McMap. All rights reserved.
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 me – Brendabrendan