Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Adds Git.logBetween(from, to, callback) #9

wants to merge 1 commit into from

3 participants


I needed to get the log between two refspecs, and that's what Git.logBetween allows.

Given a from refspec, and a to refspec it returns an array of commit hashes, ordered by commit time.

I lifted the parsing of an individual line of the summary log from logFile, but only for use in logBetween, since that would technically change the resulting hash if used in logFile.

If you're happy with this as a start, I can finish that refactoring for logFile to use parseSummaryLogEntry, and add some tests for logBetween


Can you squash this? 6 commits seems like a bit much for a ~30 line patch.


I can squash it into a new branch + pr if you'd like, or you can squash when you do the merge whichever works for you :-)


Squashed :-) (sorry for the delay there)


Hi Tim, when you asked Eoin if he could squash the commits, is that the same as compressing the history of changes made? What would the git command for that be?

Perhaps, this?


Hey @RaymondCrandall "sqaush" can mean a few different things.

In this case, I did an interactive rebase (rebase -i) and chose the "squash" option for each commit, reducing N commits into 1 commit.

There is also the merge --squash option when merging a branch, which takes all of the N commits in the from branch and replays them against your working copy + index leaving your index a state that represent all of the commits from that branch ready for one commit.

git help merge and git help rebase are pretty useful as is the git-scm book

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 26, 2012
  1. @ecoffey

    Adds Git.logBetween

    ecoffey authored ecoffey committed
This page is out of date. Refresh to see the latest.
Showing with 31 additions and 0 deletions.
  1. +31 −0 lib/git-fs.js
31 lib/git-fs.js
@@ -213,7 +213,38 @@ function gitExec(commands, encoding, callback) {
+var parseSummaryLogEntry = function(entry) {
+ var id = entry.match(/^commit ([a-f0-9]{40})/)[1];
+ var commit = {
+ id: id,
+ message: entry.match(/\n\n([\s\S]*)/)[1].trim()
+ }
+ entry.match(/^[A-Z][a-z]*:.*$/gm).forEach(function (line) {
+ var matches = line.match(/^([A-Za-z]+):\s*(.*)$/);
+ commit[matches[1].toLowerCase()] = matches[2];
+ });
+ return commit;
+Git.logBetween = function(from, to, callback) {
+ var commands;
+ var args = ["log", "-z", from + ".." + to]
+ gitExec(args, 'utf8', function(err, text) {
+ if (err) { callback(err); return; }
+ if (text.length === 0) { callback(null, []); return; }
+ var log = [];
+ text.split("\0").forEach(function (entry) {
+ log.push(parseSummaryLogEntry(entry));
+ });
+ callback(null, log);
+ });
var logFile = safe(function logFile(version, path, callback) {
// Get the data from a git subprocess at the given sha hash.
Something went wrong with that request. Please try again.