threads / discuss / 39013

Feature request: implement '--follow' option for `git blame`

Subject: Feature request: implement '--follow' option for `git blame`

## tl;dr

6 messages between Apr 6, 2015 and Apr 13, 2015.

replies: 5people: 3as markdown or json

KES· Apr 6, 2015, 12:12 UTC · lore
    $ pwd
    /data/mdi2/classes
    $ git blame -L22,+1 -- utils.js
    99b7a802 mdi2/utils.js (user 2015-03-26 21:54:57 +0200 22)  #comment
    $ git blame -L22,+1 99b7a802^ -- utils.js
    fatal: no such path mdi2/classes/utils.js in 99b7a802^
As you have noticed, the file were in different directory in that commit
    $ git blame -L22,+1 99b7a802^ -- ../utils.js
    c5105267 (user 2007-04-10 08:00:20 +0000 22)    #comment 2
Despite on doc
    The origin of lines is automatically followed across whole-file renames (currently there is no option to turn
           the rename-following off)
blame does not follow renames. Why?
**UPDATE:** Short answer
`git blame` follow renames but not for `git blame COMMIT^ -- <filename>`

But this is too hard to track file renames manually through bulk of renames and ton of history. I think, this behaviour must be fixed to silently follow renames for `git blame COMMIT^ -- <filename>`. Or, at least, `--follow` must be implemented, so I can: `git blame --follow COMMIT^ -- <filename>`

The good answer is here: http://stackoverflow.com/questions/29468273/why-git-blame-does-not-follow-renames

KES· Apr 7, 2015, 17:26 UTC · re: KES · lore

Fwd: Feature request: implement '--follow' option for `git blame`

-------- Пересылаемое сообщение -------- 06.04.2015, 15:12, "KES" <kes-kes@yandex.ua>:

    $ pwd
    /data/mdi2/classes
    $ git blame -L22,+1 -- utils.js
    99b7a802 mdi2/utils.js (user 2015-03-26 21:54:57 +0200 22)  #comment
    $ git blame -L22,+1 99b7a802^ -- utils.js
    fatal: no such path mdi2/classes/utils.js in 99b7a802^
As you have noticed, the file were in different directory in that commit
    $ git blame -L22,+1 99b7a802^ -- ../utils.js
    c5105267 (user 2007-04-10 08:00:20 +0000 22)    #comment 2
Despite on doc
    The origin of lines is automatically followed across whole-file renames (currently there is no option to turn
           the rename-following off)
blame does not follow renames. Why?
**UPDATE:** Short answer
`git blame` follow renames but not for `git blame COMMIT^ -- <filename>`

But this is too hard to track file renames manually through bulk of renames and ton of history. I think, this behaviour must be fixed to silently follow renames for `git blame COMMIT^ -- <filename>`. Or, at least, `--follow` must be implemented, so I can: `git blame --follow COMMIT^ -- <filename>`

The good suggestion is here: http://stackoverflow.com/questions/29468273/why-git-blame-does-not-follow-renames -------- Завершение пересылаемого сообщения --------

Junio C Hamano· Apr 8, 2015, 02:48 UTC · re: KES · lore

Re: Feature request: implement '--follow' option for `git blame`

KES <kes-kes@yandex.ua> writes:
> **UPDATE:** Short answer
>
> `git blame` follow renames but not for `git blame COMMIT^ -- <filename>`
Suppose you have file A and file B in your version v1.0.

Six month down the road, the code was much refactored, and you do not need the contents of these two files separately. You have removed A and B and much of what they had is now in file C. That is the current state.

    git blame -C HEAD -- C

may follow the contents from both just fine, but if you _were_ allowed to say

    git blame v1.0 -- C

what does it even mean? C did not exist v1.0 at all. Are you asking to follow the contents of A back then, or B? How did you tell you meant A and not B when you told it C in this command?

"git blame" follows content movements, and never treats "renames" in any special way, as it is a stupid thing to do to think a rename is somehow special ;-)

The way you tell what content to start digging from to the command from its command line is to give starting point commit (defaults to HEAD but you may give COMMIT^ as your example) and the path in that starting point. As it does not make any sense to tell C to Git and then magically make it guess you meant A in some cases and B in some other. If v1.0 did not have C, the only sensible thing to do is to exit instead of making a guess (and without telling the user how it guessed).

Eugen Konkov· Apr 10, 2015, 06:40 UTC · re: Junio C Hamano · lore

Re[2]: Feature request: implement '--follow' option for `git blame`

Здравствуйте, Junio.
Вы писали 8 апреля 2015 г., 5:48:36:
JCH> KES <kes-kes@yandex.ua> writes:
>> **UPDATE:** Short answer
>> `git blame` follow renames but not for `git blame COMMIT^ -- <filename>`

JCH> Suppose you have file A and file B in your version v1.0. .... As it does not make any sense to tell C to Git and JCH> then magically make it guess you meant A in some cases and B in some JCH> other. If v1.0 did not have C, the only sensible thing to do is to JCH> exit instead of making a guess (and without telling the user how it JCH> guessed).

I agree with your complex example. But it will be great to guess in simple case, when in version v1.0 only one file A which were renamed into C half year later.
`git blame COMMIT^ -- C`

For complex example the clue will be if user supply line number he want to blame. So if user supply line 10 we follow A, if user supply 30 we follow B. Simple and great =) (I mean usefull for people)

`git blame --line 10 COMMIT^ -- C` `git blame --line 30 COMMIT^ -- C`

-- 
С уважением,
 Eugen                          mailto:kes-kes@yandex.ru
Junio C Hamano· Apr 13, 2015, 05:32 UTC · re: Eugen Konkov · lore

Re: Feature request: implement '--follow' option for `git blame`

Eugen Konkov <kes-kes@yandex.ru> writes:
> I agree with your complex example.

Note that it is a norm, not anything complex, that we do not rename a file wholesale.

> But it will be great to guess in simple case, when in version v1.0
> only one file A which were renamed into C half year later.

So you used to have A and somebody renamed that into C in the past. The content of C in the current version is what you used to have in A.

What should happen if you also have A, whose contents do not have any relation to that old A, in today's code?

What should happen if you also used to have C, whose contents do not have any relation to that old A or current C?

What happens if you added such random guessing and you were not so familiar with the project history to know these unrelated A's and C's that used to exist in the past?

Current Git _consistently_ behaves, even in the presense of anything that can lead to confusing behaviour. When you ask

    git blame OLD -- A

it does not matter if you have an unrelated A in the revision that you happen to have checked out in your working tree (i.e. HEAD). The above command line talks about the old revision OLD and A talks about the path A in that old revision.

Eugen Konkov· Apr 13, 2015, 19:07 UTC · re: Junio C Hamano · lore

Re[2]: Feature request: implement '--follow' option for `git blame`

Здравствуйте, Junio.
Вы писали 13 апреля 2015 г., 8:32:33:
JCH> Eugen Konkov <kes-kes@yandex.ru> writes:
>> I agree with your complex example.

JCH> Note that it is a norm, not anything complex, that we do not rename JCH> a file wholesale.

>> But it will be great to guess in simple case, when in version v1.0
>> only one file A which were renamed into C half year later.

JCH> So you used to have A and somebody renamed that into C in the past. JCH> The content of C in the current version is what you used to have in JCH> A.

JCH> What should happen if you also have A, whose contents do not have JCH> any relation to that old A, in today's code?

JCH> What should happen if you also used to have C, whose contents do not JCH> have any relation to that old A or current C?

JCH> What happens if you added such random guessing and you were not so JCH> familiar with the project history to know these unrelated A's and JCH> C's that used to exist in the past?

JCH> Current Git _consistently_ behaves, even in the presense of anything JCH> that can lead to confusing behaviour. When you ask

JCH>     git blame OLD -- A

JCH> it does not matter if you have an unrelated A in the revision that JCH> you happen to have checked out in your working tree (i.e. HEAD). JCH> The above command line talks about the old revision OLD and A talks JCH> about the path A in that old revision.

Yes. you are right. I do not think about these examples.
-- 
С уважением,
 Eugen                          mailto:kes-kes@yandex.ru

← back to recent threads