简体   繁体   中英

git diff --name-only with no file paths

How do I execute the following command getting filenames without paths?

So, literally, what the command says, "name-only" - not the file paths, just the file names.

git diff --name-only <commit> <commit>

AFAIK this is not provided by git since this is a pretty unusual requirement. For example my first try in my repository yielded about a dozen lines, each saying pom.xml because I just created a new version.


You can use a small script though. basename is your friend here.

I like xargs so I'd do it like this

git diff --name-only <commit> <commit> | xargs -n1 basename

This will fail if git diff provides no output.

Or for a loopy version

for s in `git diff --name-only <commit> <commit>` ; do basename $s ; done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM