1

Suppose a commit X changes line 500 of the file foo.java. I want to see all the past commits that have changed this line.

Inspired by this thread, I understand that since git 1.8.4, we can use the -L option of git log to view the evolution of a specific line range. So I use git log -L 500,500:foo.java

However, I got a error saying

file foo.java has only 450 lines

I suspect that the reason is that my git log command operates on the HEAD. But between commit X and HEAD, the file foo.java has been modified and ended up with only 450 lines.

So, how can I get all the commits that have changed this line 500 from commit X?

Community
  • 1
  • 1
Ida
  • 2,919
  • 3
  • 32
  • 40

1 Answers1

0

You could try that same command for each SHA1, with git rev-list

windows (with Gnu On Windows for the xargs command)

git rev-list HEAD|xargs git log -1 -L 500,500:foo.java 2>NUL

Unix:

git rev-list HEAD|xargs git log -1 -L 500,500:foo.java 2>/dev/null
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • May you explain a bit more about the command? Where should I put the commit SHA1? What is `HEAD|xargs` and `2>/dev/null`? Thanks a lot! – Ida Jul 21 '14 at 07:20
  • @lda that is basic scripting, using redirection unix.stackexchange.com/questions/70963/difference-between-2-2-dev-null-dev-null-and-dev-null-21, and pipe |. You don't have to put a SHA1: git rev-list is supposed to list *all* SHA1 for you in your repo. – VonC Jul 21 '14 at 07:22
  • @lda But if you have to put a SHA1 '`X`', you can use `git rev-list X..HEAD`: Replace '`X`' by your SHA1. – VonC Jul 21 '14 at 07:24
  • 2
    thanks, but I got an error using your command (without the 2>NUL part): `fatal: More than one commit to dig from: a7d7f9e4036bff9ab524b88cb8210c97ef36bc9c and 24767679c82f94eab5d81346bdbdf63f8bdbca36?` – Ida Jul 21 '14 at 07:47
  • @lda are you on Windows? are you using a simple cmd session or git-bash? – VonC Jul 21 '14 at 08:07
  • @lda then why are you using the Windows syntax? – VonC Jul 21 '14 at 08:12
  • Sorry, I meant I used your command without the last part. The command is `git rev-list HEAD|xargs git log -1 -L 500,500:foo.java` – Ida Jul 21 '14 at 08:19