utnapistim
utnapistim

Reputation: 27365

How do I find the git revision where certain files were added?

Background:

We added some files to our git repository, from another project. Then, we patched these files (over the course of about six months) to support particularities of our application's implementation.

Now, I need to propagate those changes into the project where the files were initially taken from.

I tried to get a list of modified files, between the revision we added them at and the head of the dev branch:

The problem is I cannot find the revision(s) where these files were added to the project.

I tried getting diffs using a prior revision number (one that would be old enough to be at the beginning of our changes):

$ git diff c5362a135d..dev_branch -- subdir/where/the/files/are/at

(in this example, c5362a135d is a revision from before these files were added).

If I diff between c5362a135d and the current HEAD, I cannot see the diffs (only full file listings):

diff --git a/dir/subdir/file.h b/dir/subdir/file.h
new file mode 100644
index 0000000..387b33b
--- /dev/null
+++ b/dir/subdir/file.h

....

Question:

How do I find the git revision where some file/directory was added to the repository?

(so that current revision of the file will not be diff-ed with /dev/null, but with the file that was originally added).

Environment:

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=lucid
DISTRIB_DESCRIPTION="Ubuntu 10.04.4 LTS"

$ $ git --version
git version 1.7.0.4

Upvotes: 1

Views: 190

Answers (1)

Schleis
Schleis

Reputation: 43690

For one file if you do git log <filename> you will get only the commits for that file up-to when the file was added to the repository. Not sure how many files that you have or if they were all added at the same time but that should get you what you need.

UPDATE:

If the file will have been renamed or moved use the --follow option per comment from @Treze, also per this answer (https://stackoverflow.com/a/11533206/498699) you can use the --oneline and tail to get the last commit:

git log --follow --oneline <filename> | tail -n 1

Upvotes: 1

Related Questions