0

Sorry if this sounds easy but I seem to be struggling with some of the more advanced GIT commands.

I am basically trying to find modified line numbers in files that have not been committed yet. Just staged. Im able to get the file names using:

git diff --cached --name-only --diff-filter=ACMR HEAD

Assuming I have an array of file names:

$changedFilesList = [0 => 'file1.php', 1 => 'file2.php'];

However what I am also interested in getting are the actual line numbers within those files where code was modified. Basically do a diff with the current checked out branch and wherever there are differences, get the line numbers also.

Any tips ?

UPDATE: I have looked at others solutions on stack overflow but they are heavy on bash scripting side. I am looking for a GIT specific or PHP solution.

kratos
  • 2,465
  • 2
  • 27
  • 45
  • Possible duplicate of [Git diff with line numbers (Git log with line numbers)](https://stackoverflow.com/questions/24455377/git-diff-with-line-numbers-git-log-with-line-numbers) – bfontaine Sep 29 '17 at 17:37
  • I saw that question earlier but that is heavy on bash side. I am looking for a GIT/PHP specific solution if possible. Sorry for confusion. – kratos Sep 29 '17 at 17:40
  • The accepted answer is all about git, there’s no Bash in here. – bfontaine Sep 29 '17 at 17:41
  • Yes read the very last sentence of the answer: 'As you can probably tell, unified-diff format doesn't make it easy to figure out line numbers (at least if you're not a machine). If you really want line numbers that you can read, you'll need to use a diffing tool that will display them for you.' – kratos Sep 29 '17 at 17:44
  • 1
    Right, you need some PHP code to parse the diff and get the line numbers. I retracted my close vote. – bfontaine Sep 29 '17 at 17:46
  • `git blame -s -- ` output in the format of ` ) `. If `sha` is `00000000`, it's a modified but not committed line. `n` is the line number. `content` is what the line is. It's not that heavy for `bash` to parse the output and get the line number. For example `git blame -s -- | grep ^00000000 | tr -d ')'`. But if you prefer PHP, you could write a PHP solution to parse the output. – ElpieKay Sep 30 '17 at 02:17
  • @ElpieKay but the file is not committed yet.. – kratos Oct 02 '17 at 14:48
  • @kratos do you mean "not tracked yet"? If it's a new file and not added yet, it's untracked. – ElpieKay Oct 02 '17 at 15:19

1 Answers1

0

Install meld, then after type in your shell git difftool -d /remote/your_project. It will open a window which will meet your need.

bfontaine
  • 18,169
  • 13
  • 73
  • 107
Argus Malware
  • 773
  • 7
  • 19