JaSn
JaSn

Reputation: 229

See git a list of all commits that went between two commits (across branches)

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):

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?

Upvotes: 3

Views: 2247

Answers (2)

JaSn
JaSn

Reputation: 229

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.

Upvotes: 1

Gauthier
Gauthier

Reputation: 41945

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.

Upvotes: 3

Related Questions