28

I'm using the github windows shell and I'll do the following

git status

see a list of modified files and want to remind myself what's changed. I'll have to type something like

git diff Source\FooBar\Pages\FooBar.aspx

That seems like a lot of characters to have to type. Is there some easier workflow to look at diffs that I'm not seeing?

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
user76379
  • 281
  • 3
  • 3
  • This would be better served on SO as it deals with programming tools/implementation and not conceptual/design issues. Please do not re-ask it there as this can be migrated. A good rule to follow is if your question has you in front of your IDE it belongs on SO. If it has you in front of a whiteboard it belongs on Programmers. – Walter Dec 31 '12 at 23:36
  • What specifically do you want to avoid? Do you want to avoid having to see the diff of each file individually? Do you want to get the diff of a particular file without typing the full path? – akton Jan 01 '13 at 09:33
  • I specifically want to avoid typing the entire path for each file I want to `git diff` – user76379 Jan 01 '13 at 14:22

5 Answers5

39
git diff -- **/FooBar.aspx

In general * stands for any part of a filename while ** stands for any subpath. E.g. git diff -- **/main/**/*.aspx will diff only aspx files that are residing somewhere in a subdirectory of main or main itself. This applies to other commands that accept paths, like commit and add.

jartur
  • 509
  • 4
  • 6
1

If you want to review all changes, you can simply use git diff. It will not list new files, though.

To selectively look at changes, I would recommend to use a GUI, e.g., git gui or gitk.

Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239
1

I use Console2 to host bash.

With this I'm able to use Ctrl + Click and Drag to highlight text which can then be copied to the clipboard and pasted into further command lines.

I use this to copy file paths.

This enabled me to type git diff [Ctrl+V] and get the command line I want.

Rory Becker
  • 15,551
  • 16
  • 69
  • 94
1

most terminals (e.g. console2 for windows) have auto-completion.

start typing and press tab

usually git can auto-complete after 2 characters. like:

gi tab di tab

will give you git diff. if your folders are not named similarly than it might auto-complete after a single character. like if your project root had three files:

  • readme
  • /source/
  • /bin/

you could simply type r, s, or b then tab to auto-type any of those file names.

fyi, auto complete works for terminal and git commands, file and directory names, branch and tag names, but unfortunately not for commit ids.

xero
  • 4,077
  • 22
  • 39
  • 1
    autocomplete works for the gi `tab` di `tab` part but then not for the filename part. which, when your filename is usually something long like `Source\FooBar\Pages\FooBar.aspx` it makes it really frustrating to use – user76379 Jan 27 '13 at 03:19
  • that is totally not true (in windows msysgit, which i use). i just tried it in an open repo. `gi` tab `di` tab `st` tab `c` tab... becomes `git diff style/css/` it auto types the slashes an everything. – xero Jan 29 '13 at 20:02
0
# A quick and crude idea:
function gitdiff()
{
  # git diff returns repo relative names, so we must add the
  # the git root, i.e. parent of the git dir.
  # This may not work in all git repo styles?
  local GIT_FILES_ROOT="$(git rev-parse --git-dir)/.."
  git diff -- "${GIT_FILES_ROOT}/${1}"
}
function _dp_git_diff_complete()
{
  local cur
  cur=${COMP_WORDS[COMP_CWORD]}
  COMPREPLY=($(git diff --name-only | \egrep "^$cur"))
}
complete -F _dp_git_diff_complete gitdiff

# However, you must use:
# $ gitdiff [prefix]<tab>
# not:
# $ git diff [prefix]<tab>
# because I don't know how to make a completion for a multi-word command,
# e.g. git diff.
# Of course, you can use any other name you'd like besides `gitdiff'
# This will suck if the diff command needs additional options or parameters.
# There are ways to tell the completion API to handle options, but it's not a
# short topic.