1

Is there a way to specify a partial file name in order to save keystrokes?

Instead of:

git diff path/path/path/path/path/somefilename.js

To something like:

git diff *somefilename.js

Or:

git diff .somefilename.js
2
  • ./somefilename.js should work. Commented May 22, 2015 at 0:33
  • fatal: ambiguous argument './app.js': unknown revision or path not in the working tree. is Git searching all files? not just what's staged/unstaged? Commented May 22, 2015 at 0:36

2 Answers 2

4

git diff -- "**/somefilename.js"

Sign up to request clarification or add additional context in comments.

3 Comments

that worked. though it looks kinda cryptic. -- with no arguments? or is that an "implied" argument?
@culturalanomoly: The -- option is a convention that means "this is the end of the options", which is rather important if you happen to have any paths that happen to start with --.
The -- is especially to disambiguate a <commit> from a path, in case there are paths and refs with the same name, since diff allows you to diff against specific commits. The quotes are needed to disable shell globbing. If this works for you please accept the answer.
1

Not git-based, but I often use something like

<command> $(git ls-files | grep 'somefilename.js')

to specify a file with a basename that is unique in the repository. In this case, that would be git diff $(git ls-files | grep 'somefilename.js'.

git ls-files will list all the files tracked in your repo. You can then grep for the basename to get the full name of the file. By doing that in a subshell ($(...)) you can interpolate that full name into whatever command you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.