Search code examples
gitbashxargs

Bash / xargs trick to open all files that changed in git HEAD


I open files from Terminal in Sublime Text and do so using a shortcut like this:

$ subl <filename>

...what I'm hoping to do is open all files that changed in my last git commit.

I can see all files that changed like so:

$ git show --name-only HEAD
commit b2c891f64daab0dc67df5cde9608602c7cde2f7b
Author: Jacob
Date:   Fri Jun 9 16:52:05 2017 -0700

    start doing some cool stuff; ref 12345

python/deep/hot/Classes.py
python/shallow/cold/features.tmpl
javascript/utility_master.js

... but this command shows more info besides the filenames themselves.

I want to do something like:

$ git show --name-only HEAD | <get the lines out that aren't filenames> | xargs -i subl {}

Does this require awk? Or a different git flag that I can't find?


Solution

  • Use diff: git diff --name-only HEAD~

    subl `git diff --name-only HEAD~`