How can I run 'git diff some / long / file / name' without entering the full path?

In my workflow, I often run the following pair of commands:

$ git status M README.txt M some/long/file/name $ git diff some/long/file/name 

Is there a way to quickly enter / use _shortcat for a long file name without copying the name (you need to use a mouse for this action, and it's not as fast as typing)? Maybe something like git diff $2 , where $2 is the second modified file from the list of states ...?

+7
git command-line-interface git-status git-diff
source share
5 answers

This tool (SCM Breeze) can do what you need, in particular, see this part of the documents

enter image description here For example, if ga was your alias for git add, instead of entering text, something like:

 $ ga assets/git_breeze/config* assets/git_breeze/install.sh You can 

enter this instead:

 $ ga $e2 $e3 $e11 

But SCM Breeze aliases ga to git_add_shortcuts is a function that is smart enough to extend integers and ranges, so all you need to do is enter:

 $ ga 2 3 11 

I think this suits your needs better than the solutions that are in the post I linked in my comment above.

+4
source share

Another way you can do this without installing a separate tool is to disable git status output and pass it through sed, and then return to git diff. Its a long command, so you can put it in your .bashrc and alias. For example, putting this in my .bashrc:

  myfunction() { git status --porcelain | sed -n "${1} s/^...//p' | xargs git diff } alias gd=myfunction 

Then i can do

 >> git status M main.cpp M tipsy.cpp M other.cpp >> gd 2 

And the output of git diff is the second file.

EDIT: I combined the two seeds into one because the two separate were stupid.

+4
source share

You can also use * placeholders as suggested in this answer . Usually you do not need to enter the full file name, for example,

 git diff -- **/name 

Given that a short segment of the name, for example. "na", unique to the list of modified files, you can also do something like this:

 git diff -- *na* 

Thus, you do not need to count records to find out what number he should use.

+2
source share

I found another way (but "SCM Breeze" is awesome and my main tool): I use https://github.com/junegunn/fzf fuzzy-search with an alias:

 alias gfz="git status -s --porcelain | cut -c 4- | fzf" git diff $(gfz) 
0
source share

only

 git diff 

Or:

 git diff --cached 

Then scroll using the keyboard.

-3
source share

All Articles