Your file is already staged to be committed. You can show it's diff using the --cached option of git. To unstage it, just do what git status suggests in it's output ;) You can check The Git Index For more info.
- means "old", as we usually invoke it as diff -u old new . +1,4 means that this piece of the second file starts at line 1 and shows a total of 4 lines. Therefore it shows lines 1 to 4. + means "new". We only have 4 lines instead of 6 because 2 lines were removed!
Use:
git diff --name-only
Go forth and diff!
Line numbers as in number of changed lines or the actual line numbers containing the changes? If you want the number of changed lines, use git diff --stat
. This gives you a display like this:
[me@somehost:~/newsite:master]> git diff --stat
whatever/views/gallery.py | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
There is no option to get the line numbers of the changes themselves.
Note: if you're just looking for the names of changed files (without the line numbers for lines that were changed), see another answer here.
There's no built-in option for this (and I don't think it's all that useful either), but it is possible to do this in Git, with the help of an "external diff" script.
Here's a pretty crappy one; it will be up to you to fix up the output the way you would like it.
#! /bin/sh
#
# run this with:
# GIT_EXTERNAL_DIFF=<name of script> git diff ...
#
case $# in
1) "unmerged file $@, can't show you line numbers"; exit 1;;
7) ;;
*) echo "I don't know what to do, help!"; exit 1;;
esac
path=$1
old_file=$2
old_hex=$3
old_mode=$4
new_file=$5
new_hex=$6
new_mode=$7
printf '%s: ' $path
diff $old_file $new_file | grep -v '^[<>-]'
For details on "external diff", see the description of GIT_EXTERNAL_DIFF
on the Git manual page (around line 700, pretty close to the end).
Use:
git diff master --compact-summary
The output is:
src/app/components/common/sidebar/toolbar/toolbar.component.html | 2 +-
src/app/components/common/sidebar/toolbar/toolbar.component.scss | 2 --
This is exactly what you need. The same format as when you are making a commit or pulling new commits from the remote.
PS: It's weird that nobody answered this way.
1) My favorite:
git diff --name-status
Prepends file status, e.g.:
A new_file.txt
M modified_file.txt
D deleted_file.txt
2) If you want statistics, then:
git diff --stat
will show something like:
new_file.txt | 50 +
modified_file.txt | 100 +-
deleted_file | 40 -
3) Finally, if you really want only the filenames:
git diff --name-only
Will simply show:
new_file.txt
modified_file.txt
deleted_file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With