0

Is it possible to add a list of files somewhere to a changelist or file or something, and to run git diff commit1 commit2 myListOfFiles and to get the diff of just that list of files? Or is it possible to create a macro that expands to that list? and to be able to remove and add from that list or change it?

This would be super-useful for creating patches for just certain files, not having to type down the paths for all 20 files I want to diff.

Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140

1 Answers1

1

Simply do:

git diff commit1 commit2 -- $(cat /path/to/listfile)

You can alias this command by the following line to your .gitconfig:

[alias]
    listdiff = "!f() { git diff $1 $2 -- $(cat \"$3\"); }; f"

and call it with

git listdiff commit1 commit2 path/to/file
kirelagin
  • 13,248
  • 2
  • 42
  • 57
  • this is a very good method to go, I'll use it till something better comes along, thanks! :) I see that you can do some bash-like scripting in the `gitconfig`. Isn't it possible to keep these files inside `gitconfig`, not other file? Also can you give me some link to some references regarding this kind of scripting inside `gitconfig`? – Jacob Krieg Jun 14 '13 at 06:28
  • 1
    @JasonSwartz What do you mean “other file”? You can put this in any git config, that is `~.gitconfig`, `.git/config`, `/etc/gitconfig` and so on, see [`man git-config`](https://www.kernel.org/pub/software/scm/git/docs/git-config.html) for details. If you start an alias with `!`, the rest of the line is simply executed in your shell, so, this is not “bash-like”, that's true bash (or whichever shell you use). – kirelagin Jun 14 '13 at 10:47
  • I meant, not to keep a separate file for the list of files. to store that list of files in the `gitconfig`. – Jacob Krieg Jun 14 '13 at 13:53
  • @JasonSwartz Seems quite useless? I mean, you normally want to have one such file per repo, so keeping it in `.gitconfig` doesn't make any sense. – kirelagin Jun 14 '13 at 21:52