Reputation: 481
For example I have the following files in tag: v1.0.1
a
b
c
and for tag: v1.0.2
the files are as follows:
a
b
c
d
e
Now how do we get the list of new files present in the repo for the latest tag ?
The answer for the above example should be:
d
e
Upvotes: 0
Views: 17
Reputation: 488163
A tag identifies a commit. A commit contains a snapshot—a set of files.
git diff
compares sets-of-files, including two different snapshots. Simply point git diff
at two specific commits—two snapshots—and it will give you instructions for converting one to the other:
git diff v1.0.1 v1.0.2
The only problem is that git diff
shows you the complete instructions by default, while you want to know what files are affected. Fortunately git diff
has knobs you can turn to make it reduce or change its output, such as --name-status
:
$ git diff --name-status v1.0.1 v1.0.2
M Makefile
M debian/changelog
M quote.c
M server-info.c
The "status" letter at the front tells you what Git thinks happened to the file: M
means "modified", "D" means "deleted", and so on. The most interesting for your particular case is A
, which means "added": the file is in the second commit, but not in the first.
Hence, you want to select the files from this list that have status A
(in my example none do but in your example some will). Fortunately git diff
has a knob for this as well:
git diff --diff-filter=A <options> <arguments>
You could keep the --name-status
so that it doesn't show the contents of the files, but this will still show the letter A
; so you will want --name-only
to print just the names:
git diff --name-only --diff-filter=A v1.0.1 v1.0.2
and you're done.
Upvotes: 2