GIT: Find commits for a specific file

git log --stat component/src/main/resources/META-INF/spring/context-osgi.xml

 Gets you a list of all the commits including that file.

git diff $commit_hash_old $commit_hash_current component/src/main/resources/META-INF/spring/context-osgi.xml

Shows you the diffs between the old file and the one you have now.

Cross ref: git blame might be more useful. Tells you which lines of a file were changed by whom:

git blame component/src/main/resources/META-INF/spring/context-osgi.xml

6d4e6fd3 (Dick Dastardly 2012-07-26 15:28:33 +0100 24) VirtualTopic.com.some.co.error.DLC
6d4e6fd3 (Dick Dastardly 2012-07-26 15:28:33 +0100 25) /data/error/
c3cedfe7 (Dick Dastardly 2012-06-13 16:10:19 +0100 26)
6d713a0a (Muttley 2012-10-18 13:44:33 +0100 27)
3233b294 (Peter Perfect 2012-11-07 13:16:34 +0000 28) mappingPersistenceUnit
3233b294 (Peter Perfect 2012-11-07 13:16:34 +0000 29) HSQL
c3cedfe7 (Dick Dastardly 2012-06-13 16:10:19 +0100 30) org.apache.openjpa.jdbc.sql.HSQLDictionary
c3cedfe7 (Dick Dastardly 2012-06-13 16:10:19 +0100 31) org.hsqldb.jdbc.JDBCDriver
47e39616 (Dick Dastardly 2012-06-21 14:12:40 +0100 32) jdbc:hsqldb:data/resource/lookup.db
3233b294 (Peter Perfect 2012-11-07 13:16:34 +0000 35) 1

Git locally, Subversion Repos

Whilst learning how to use git with svn starting from a new item in the trunk, I’ve hit a couple of snags and am documenting the way I should have done it.

  • Create your new working directory and add it to svn first: mkdir efot && svn add efot && svn commit efot -m "starting the new project"
    (Note the revision number for later)
  • Make sure svn will ignore git files: svn ps svn:ignore ".git" efot
  • Now we go to setup git: cd efot
  • Initialise git: git svn init https://svnServer/repos/section/trunk/efot
  • Get the right revision from svn using the revision number you got in 1: git-svn fetch -r2424
  • Make sure everything is really, really, really ready ;): git-svn rebase
  • Make sure git ignores .svn:
    • vim .git/info/exclude
    • add “.svn” (without the quotes) to the bottom of the file
    • save and quit.
  • At this point you’re ready to go. Create your usual directory structure and add it to git: git add .
  • Do your first commit to git: git commit
  • Add a file: touch showMe.txt
  • add to git: git add .
  • commit to git: git commit -a
  • update from svn: git-svn fetch
  • if any come in on teh fetch, replay your git changes onto it: git-svn rebase
  • commit to svn: git-svn dcommit

Job’s a good’un. Thanks to Flavio Castelli