xrage
xrage

Reputation: 4800

How to extract different file versions between two tags in Git?

Methods like mentioned here Get list of new commits between two tags in Git? gives me list of diff files.

However, I have a constraint like I can't checkout every time to a tag because I need to serve more than 1000 request/sec asking diff files between different tags. Is there any method available to achieve this?

For example, I have 3 tags:

Now assume a file one.txt changes in all tags and head is on latest tag (1.2). Now when I do

git diff 1.0 1.1 --stat

it returns me file name one.txt so now I know that one.txt is changed, and I can grab that file. However, to get one.txt on tag 1.1, I need to checkout first at 1.1, otherwise I will get latest one.txt, so here I need to avoid that checkout and get the one.txt as it was on 1.1.

Please suggest any solution?

Upvotes: 3

Views: 308

Answers (1)

user456814
user456814

Reputation:

Solution 1: git checkout

Using git checkout with a revision specifier like a branch, tag, or commit sha, along with a filepath, will checkout that revision of the file into your working copy:

git checkout <tag> -- <filepath>

Note that this only modifies the version of that one particular file. The rest of your working copy will not be affected.

Documentation

From the official Linux Kernel documentation for git log (summarized):

git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>…

When <paths> or --patch are given, git checkout does not switch branches. It updates the named paths in the working tree from the index file or from a named <tree-ish> (most often a commit)...The <tree-ish> argument can be used to specify a specific tree-ish (i.e. commit, tag or tree) to update the index for the given paths before updating the working tree.

Solution 2: git show

You can also retrieve a version of a file using git show and outputting the results to a file:

git show <tag>:<filepath> > <outputPath>

See Also

Official Linux Kernel documentation for:

Upvotes: 3

Related Questions