2

How do I know when a branch (or a commit) was merged into another branch? For example - given I have branch1 and master and, sometime in the past, branch1 was merged into master, how can I know when a specific commit was introduced into the main branch? As far as Git cares, once the commit is reachable from master, it's there.

See example (windows) script to illustrate the problem:

rd .git /s /q
del data.txt

git init

echo 1 > data.txt
git add data.txt
git commit -m initial_commit_master

git checkout -b branch1
echo 2 > data.txt
git add data.txt
git commit -m commit_in_branch1

git checkout master
git merge branch1

echo 3 > data.txt
git add data.txt
git commit -m 2nd_commit_master

How do I recognize that "2" (in data.txt) came from branch "branch1" and the earliest point it was joined to master?

Edit 1: An example use case - since we deploy from master, I'm interested to know when a specific change was actually introduced to production. I know it's in master now ("2" was in master at some point) - but I don't know when it was put into master because all I see is the image today, not the image that was.

Ran Biron
  • 6,317
  • 5
  • 37
  • 67

3 Answers3

1

The exact answer is : you can't do it in a 100% reliable way. For example, you may delete the branch1 branch, and git won't keep any trace of the commit's original branch.

That being said :

You can find the commit(s) which introduced a "2" in data.txt, using git log -Sword :

git log -S2 -- data.txt

Once you have targeted the commit you are looking for, you can find the branches (that still exist) which contain the given commit :

git branch --contains <hash>

references :
How to grep Git commit diffs or contents for a certain word?
How to list branches that contain a given commit?

Community
  • 1
  • 1
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • 1
    I know these :). Since we deploy from master, I'm interested to know when a specific change was actually introduced to production. I know it's in master _now_ - but I don't know when it was put into master. – Ran Biron Jul 29 '14 at 09:50
1

This GitHub repo does what you need.

TomL
  • 759
  • 8
  • 20
0

I was looking around to find something similar - get the timestamp of when a change was pulled/merged into your current branch. I wanted this info so that I could see when exactly I moved (pulled/merged) some changes to the master branch of a production environment. And this is what I found is useful:

Command: git reflog show --date=default

Output:

5c4f140 HEAD@{Mon Aug 10 05:36:24 2015 +0000}: pull origin: Fast-forward 1ba6e4e HEAD@{Wed Aug 5 14:40:50 2015 +0000}: pull origin: Fast-forward 05382e4 HEAD@{Wed Jul 22 12:27:20 2015 +0000}: pull origin: Fast-forward bad194c HEAD@{Wed Jul 22 09:54:01 2015 +0000}: pull origin: Fast-forward 016f6cb HEAD@{Sat Jul 18 04:53:56 2015 +0000}: pull origin: Fast-forward b4839d3 HEAD@{Mon Jul 6 07:35:23 2015 +0000}: pull origin: Fast-forward

Basically it shows you the commit id, and when it was merged into the current system (local).

Aswin Kumar
  • 5,158
  • 5
  • 34
  • 39