2

When we use

git diff --name-only <first tag>..<second tag>

we've got the list of changed files but by alphabetical order.

What I want is the same list but by commit/merge history order, with older at top and the newest on the bottom.

Is there a native way with a git command/option to do this?

1
  • 1
    git diff compares two points in the history, it does not access the history in between (by design). You would have to use git log instead but I don’t think there’s a built-in functionality to aggregate the file stats. Commented Jan 19, 2017 at 10:41

1 Answer 1

3

You can use git log's format option to print nothing about the commit, leaving the file name as the only thing printed:

git log --format="" --name-only <first tag>..<second tag>

As noted in the comments, git log has a --reverse option to list commits from the oldest to the newest:

git log --reverse --format="" --name-only <first tag>..<second tag>

You can also sort out duplicates using awk such that only the latest occurrence (or earliest if using --reverse) is printed

git log --format="" --name-only <first tag>..<second tag> | awk '!x[$0]++'
Sign up to request clarification or add additional context in comments.

3 Comments

That is exactly what I want but in the reverse sort. A way to have nearly what I want is to suffix your command with | tac
@saillantist missed the order part, mea culpa. git log has a --reverse option - check it out.
Thank you. I took the liberty of adding how to remove duplicates

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.