top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can `git blame` show the date that each line was merged?

+1 vote
399 views

Can git blame show the date that each line was merged to the current branch rather than the date it was committed?

Aside: in some trial and error I notice this oddity:

 $ git blame --merges
 usage: git blame [options] [rev-opts] [rev] [--] file

 [rev-opts] are documented in git-rev-list(1)
 ...

 $ git help rev-list | grep -F -e --merges
 [ --merges ]
 --merges
 --min-parents=2 is the same as --merges.
--max-parents=0 gives all
posted Jun 4, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

1) Not exactly. Git does not record when a commit entered a particular branch (or what the "ours" branch was called during a merge). If you follow a topic branch workflow in which an integrator merges each branch into master, then following the first parent of each merge will show the commits directly on master.

You can see this in action in git.git, which follows such a workflow, by doing "git log --first-parent", which shows only the commits created directly on master (mostly merges of topics, with a few trivial fixups
interspersed).

Similarly, you should be able to do "git blame --first-parent foo.c" to pass blame only along the first-parent lines. Unfortunately, while "blame" uses the regular revision code to parse its options, it does its
own traversal and does not respect each option. However, the patch to teach it about --first-parent is pretty trivial:

diff --git a/builtin/blame.c b/builtin/blame.c
index 57a487e..0fb67af 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1199,6 +1199,8 @@ static int num_scapegoats(struct rev_info *revs, struct commit *commit)
 {
 int cnt;
 struct commit_list *l = first_scapegoat(revs, commit);
+ if (revs->first_parent_only)
+ return l ? 1 : 0;
 for (cnt = 0; l; l = l->next)
 cnt++;
 return cnt;

(though I suspect it would interact oddly with the "--reverse" option, and we would want to either declare them mutually exclusive or figure out some sane semantics).
2) coming to problem of merges your problem is not the presence of "--merges" here, but that you forgot
the necessary "file" argument. Try "git blame --merges foo.c".

However, this suffers from the same problem as --first-parent, in that it is accepted but not respected. Doing so would not be impossible, but it is a little more than the two-liner above.

answer Jun 4, 2013 by anonymous
Similar Questions
0 votes

I need to provide a list of all branches I have merged into develop since a given date.
Can you recommend a git command that will do this?

+2 votes

I tend to accumulate lots of branches as I'd do one branch per feature. When cleaning up, I'd like to
delete all branches, which have been merged.

I could use

 $ git branch -d (which was merged already?) ^C
 $ git branch --merged # let's find out
 ...
 $ # Now run git branch -d with each of the branches.

This kind of question has already been discussed,
http://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-are-already-merged
suggests: git branch --merged | grep -v "*" | xargs -n 1 git branch -d

I could think of:

 $ git branch -d --merged # no need to specifiy a branch iff --merged is given with -d
 $ git branch --delete-merged # comes as an new extra option, doesn't clutter other commands
 $ git branch -d keyword-for-all-merged-branches

Before starting such a feature, I'd like to hear input of others.

+2 votes

In my Unity project, there is a native plugin, and plugin's extension is .dll, and this plugin is under git version control, when Unity is running, the plugin file will be locked.

If I merge another branch, which contains modification of the plugin, git will report error, looks like:

error: unable to unlink old 'xxxxxxx/xxx.dll' (Permission denied)

This is not bad, however, the unfinished merge action will not revert by git, a lot of changes produced in repository. Usually it makes me crazy, even worse, some of my partners are not good at using git. Of course, this problem can be avoided by quit Unity, but not every time we can remember. In my opinion, git should revert the unfinished action when the error occurred, not just stop.

+1 vote

When run that command immediate after "git bisect start" somebody sees the full commit range as defined in "git bisect start".

However running that command later after few git bisect steps" somebody is just presented with the remaining commit interval. Is this intended ?

0 votes

I want to retrieve the commit history of a given file.What command should I issue? I expect the command like below.

D:GitTest> git show --commit-history test.txt
8194aaa
c419234
...
...