2

I have two branches where commits are made independently and I would like to run a Git command that will show me all commits that went in between a certain timeframe (expressed as commit hashes) regardless of branch.

This is my test repo for the purpose of demonstration: https://github.com/jsniecikowski/testApp

If we were to imagine Git's history as a list (latest on top):

  • 4332e0e on release branch
  • 18bc14a on release branch
  • 90f9149 on master branch
  • 4f6e07f on release branch
  • ca404cf on release branch
  • 6cf47b3 on release branch

then I would like to say: 'give me all changes that happened between '90f9149' and '4332e0e'. Ideally I would get one commit: 18bc14a

My understanding is that this command would work:

git log --full-index --no-abbrev --format=raw -M -m --raw 90f9149d2f7367738e9d6f4a53c2c325f96a9b5f..4332e0eb24e18119b10835e361915f1f5eff16bc

However, this command is returning more results than expected.

Is this a bug with git, or am I missing something in my command?

JaSn
  • 209
  • 1
  • 2
  • 8
  • You might want to add `--no-merges` to take merges out of the log output. – Phil Walton Apr 23 '15 at 22:18
  • This does not change the output of unknown changes. Plus, this mechanism is used for polling for new builds, and I do want to build when a merge is committed. – JaSn Apr 23 '15 at 22:30
  • Ahhh. So you want to do continuous build/integration. Have you looked at Jenkins or teamcity yet? – Phil Walton Apr 23 '15 at 22:37
  • This question is actually a result of debugging the Git plugin for Jenkins, because that's the command it runs to poll for changes. I have a setup described [here](http://stackoverflow.com/questions/29780647/jenkins-and-git-monitor-specific-folder-on-any-branch/29788180?noredirect=1#comment47797557_29788180) that does not work as expected. – JaSn Apr 23 '15 at 22:39
  • 1
    Gotcha. For what it's worth, I looked at the log of your `Release` branch, and I see many more commits than 3 between 61641a2 and 18bc14a. https://github.com/jsniecikowski/testApp/commits/Release – Phil Walton Apr 23 '15 at 22:49
  • It might be a matter of trying to espect linear results from a non-linear versioning system. http://stackoverflow.com/questions/18679870/list-commits-between-2-commit-hashes-in-git – Phil Walton Apr 23 '15 at 23:41

2 Answers2

3

According to the repo you linked to, if you only want 18bc14a as a result, you don't want the commits that differ between master and Release, but the commits in Release that have a later date than the latest commit in master. Are you sure about this?

In that case, you can get the date of your latest commit in master with:

git log -1 master --pretty=%ad

and the commits since a date in Release with:

git log Release --since=<date>

Putting these together:

git log Release --since="$(git log -1 master --pretty=%ad)"

This also includes 4332e0e, but why wouldn't you want that? If you really don't, add a ^ after Release.

Gauthier
  • 40,309
  • 11
  • 63
  • 97
0

Gauthier's excellent answer was very close but it didn't say how to use hashes for specifying the region we want to check.

Building on top of that I did:

git log Build-Release-Testing --since="$(git log -1 90f9149d2f7367738e9d6f4a53c2c325f96a9b5f --pretty=%ad)" --until="$(git log -1 4332e0eb24e18119b10835e361915f1f5eff16bc --pretty=%ad)"

The remaining part is to eliminate the specified hashes from the return.

JaSn
  • 209
  • 1
  • 2
  • 8