When I do a git status
, I get something like this:
modified a/mega/super/duper/long/path/to/the/file/foo.php
modified a/mega/super/duper/long/path/to/the/file/another/folder/bar.php
modified a/mega/super/duper/long/path/to/the/file/someotherfolder/blahblah.php
If I want to see what has changes for the bar.php
-file (line 2) how do I do that?
I was hoping to be able to do something like this:
git diff */bar.php
git diff bar.php
And that git could tab-complete or read my mind. :-)
Idea 1: Writing it out:
It's quite extensive having to write:
git diff a/mega/super/duper/long/path/to/the/file/another/folder/bar.php
Idea 2: Use the mouse + Copy/paste
I could use the mouse and copy-paste, but that too seems like a poor solution. Taking the fingers away from the keyboard usually isn't the solution. And I have to do it quite a lot.
Idea 3: Git add patch
By running git add -p
, I automatically goes into an interactive mode, being able to do a bunch of stuff. But it's not quite what I'm after.
Idea 4: Using sed
I found this SO-question: git diff just the first file, which suggests this:
git diff $(git diff --name-only | sed -n '1 p')
I could then setup an Alfred-snippet or a bash-script that prints that. Whereafter I can change the 1
to the number of file I would like to see.
This is close to being good.
Idea 5: Bash-script to copy file-name of nth
file to clipboard
Another way would be to make a bashscript, that copies the nth
-file to the clipboard. Then I could do it in two swift commands, like this:
./copy-file-name-for-first-file-in-git-status.sh # Named to make easy to understand.
git diff [PASTE]
This would actually also solve it for the bonus-question below.
Bonus question - Same problem for git add
and git log
The same issue is present, if I don't want to do a git add .
, but want to add files individually in the deep nested folders. Then I also have to type my way through the entire path, for every single file.