Reputation: 996
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 any way, for fast typing/use_shortcat for long file name without copying it name (this action require using mouse and it's no so fast like typing)?
Maybe something like git diff $2
, where $2
is second changed file from the status list...?
Upvotes: 10
Views: 1600
Reputation: 996
I've found anouther way(But "SCM Breeze" is awesome and my primary tool): I'm using https://github.com/junegunn/fzf fuzzy-search with alias:
alias gfz="git status -s --porcelain | cut -c 4- | fzf"
git diff $(gfz)
Upvotes: 0
Reputation: 11297
You can also use *
placeholders as suggested in this answer.
Usually you don't have to type the full name of the file like this
git diff -- **/name
Given that a short segment of the name, e.g. "na", is unique within the list of modified files, you can also do something like this:
git diff -- *na*
This way you don't have to count the entries to find out which number it is that you want to diff.
Upvotes: 7
Reputation: 620
Another way you can do it without installing a separate tool is to strip the output of git status, and pipe it through sed, then back to git diff. Its a long command, so you can put it in your .bashrc and alias it. For example, putting this in my .bashrc:
myfunction() {
git status --porcelain | sed -n "${1} s/^...//p' | xargs git diff
}
alias gd=myfunction
I can then do
>> git status
M main.cpp
M tipsy.cpp
M other.cpp
>> gd 2
And the output is git diff of the second file.
EDIT: I combined the two seds into one, because having two seperate ones was silly.
Upvotes: 5
Reputation: 43314
This tool (SCM Breeze) can do what you need, specifically see this part of the docs
For example, if ga was your alias for git add, instead of typing something like:
$ ga assets/git_breeze/config* assets/git_breeze/install.sh You can
type this instead:
$ ga $e2 $e3 $e11
But SCM Breeze aliases ga to the git_add_shortcuts function, which is smart enough to expand integers and ranges, so all you need to type is:
$ ga 2 3 11
I think it suits your needs better than the solutions that are in the post I linked to in my comment above
Upvotes: 4
Reputation: 3031
Only:
git diff
Or:
git diff --cached
Then scroll with keyboard.
Upvotes: -3