This seems like a pretty straightforward question, with an answer here, but it's not quite the answer I'm looking for.
Here's the story:
I do most of my development on feature branches which are merged with develop
when the work is done. Before I merge & delete the feature branch, I like to review what I've done. To get the list of files that I'll need to review, I do this:
git --no-pager diff --name-only develop..HEAD
So, for example, I might see something like this:
file1.js
path1/file2.js
path1/file3.js
This tells me that I've made changes to those files and I need to go in & review them.
The problem is that these file paths are all relative to the root of the repository. I like to do the following to open all the relevant files in my editor:
git --no-pager diff --name-only develop..HEAD | xargs atom
If I'm currently at the root of the repository, this will open all of the files in different tabs in atom, ready for me to review them.
However, if I happen to be in a different directory (say, if I cd
ed into path1
to do something), I get a bunch of empty tabs as atom
attempts to open files that don't exist. I have to remember to cd
back to the root of the repository before starting my review.
This irritated me once too often this morning, so I went looking for a solution. I found the answer cited above which suggests adding the --relative
option to the command, like so:
git --no-pager diff --relative --name-only develop..HEAD
This sort of works, but it only gives me the files at or below the directory where I am in the repository. So, in the example above, if I've cd
ed into path1
, I'll see:
file2.js
file3.js
What I'd really like to see is:
../file1.js
file2.js
file3.js
which would allow me to pipe it to atom
and open all the files.
I did read the git help
documentation for the diff
command, and the --relative
flag does allow you to specify a path but it also excludes files outside the path.
Short of writing a very long command line like this:
pushd "$(git rev-parse --show-toplevel)" >/dev/null \
&& git --no-pager diff --name-only develop..HEAD | xargs atom \
&& popd > /dev/null
is there a way to get a list of all files changed between two commits with paths that are relative to the current directory?