1

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
utnapistim
  • 26,809
  • 3
  • 46
  • 82

1 Answers1

1

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
Community
  • 1
  • 1
Schleis
  • 41,516
  • 7
  • 68
  • 87
  • I have about 180 files to process. I will see about writing a shell script for that. – utnapistim Aug 14 '13 at 13:53
  • That doesn't seem to work for me. It doesn't seem to include the commit that actually added the file. `git blame ` shows the most recent revision to touch each line. Looking at some of my projects, I get `git blame` results older than the oldest commit that shows up in the `git log ` output. – deong Aug 14 '13 at 13:56
  • Did the file get renamed or the path changed? That can make the history difficult to follow. The last commit then would be when the file got renamed. So the earlier commits are from when the file was in its previous naming. – Schleis Aug 14 '13 at 14:01
  • You can also try the option --follow to continue listing the history of a file beyond renames. – treze Aug 14 '13 at 14:22