4

We use Git and Github. We have two main branches, staging and production. When a new project/feature is assigned to a developer they create a new branch, call it feature-branch from production, make their changes, commit, push to GitHub, and merge feature-branch with staging using GitHub. When the feature is ready to go live, the developer then merges feature-branch with production using GitHub. All merges add a merge commit.

What happened was that a developer said their feature-branch contents were on production and they never performed a merge from feature-branch to production. It is possible that someone may have merged staging with production accidentally.

Some developers make mistakes and I'm trying to figure out the root at where it happened and possibly reverse it properly. I was hoping someone could help me out.

What I'm trying to do using a combination of GitHub, Git Bash and Git Extensions is find out at what point did a particular file enter a branch. Using Git Extensions file history feature it only shows when it's changes were committed, not necessarily when it was merged into a branch.

How can I accomplish this? I've searched and used many tactics to find file logs, like git log --pretty=online <branch> -- <file> found at When was a file added to a branch in Git?.

Any extra help would be appreciated. Please let me know if you need more information and I'll be happy to provide.

Update #1

I forgot to mention this, which is probably important in this scenario. On feature-branch some changes (change-1 and change-2) were committed and merged to both staging and production. The developer then made further changes (changes-3) to his feature-branch and only merged to staging. While production should have change-1 and change-2 and not change-3, how can I find out at what point changes-3 made it's way into production?

Community
  • 1
  • 1
RoLYroLLs
  • 3,113
  • 4
  • 38
  • 57
  • Does [this](http://stackoverflow.com/questions/8475448/find-merge-commit-which-include-a-specific-commit) help? – Sascha Wolf Mar 12 '15 at 09:03

2 Answers2

3

What I'm trying to do [...] is find out at what point did a particular file enter a branch.

One issue with the problem statement is that files can be renamed, and if you simply run something like

git log --pretty=online <branch> -- <file>

only commits in which the file in question was called <file> will be listed. However, the git log flag called --follow is right up your alley; see the git-log man page:

--follow

Continue listing the history of a file beyond renames (works only for a single file).

Here you want to run

git log --reverse --follow <branch> -- <file-in-question>

The top log entry will corresponds to the oldest (in the chronological sense) commit in which <file-in-question> appears. If you want to get the oldest (in the topological sense) commit in which <file-in-question> appears, you need to add the --topo-order flag to the command above.

jub0bs
  • 60,866
  • 25
  • 183
  • 186
  • Thanks for enlightening me about the `--follow` argument. However, the last commit does not seem to be the commit at which the file was introduced to the branch. Good catch concerning the file renamed situation. The commit given from the command above is the commit at which the file was renamed. I just realized I left out a piece of info and will add it as `update#1` above. it might make a difference. – RoLYroLLs Mar 11 '15 at 18:50
-1

git blame <filename> will give you line by line details of file with commit id and commiter name and datetime.

Tudor Timi
  • 7,453
  • 1
  • 24
  • 53
Rohit Nair
  • 11
  • 5
  • 1
    Thanks. However, this only shows on which commit each line was committed. I'm trying to find out when, commit bdc45b, was merged into the `production` branch. – RoLYroLLs Mar 11 '15 at 19:08