Hmmm, I know Subversion doesn’t do it any better, but I was led to believe Git tracked directory renames. At least, it didn’t behave as I expected. Here’s a reproduction recipe:

repro.sh
 1 #!/bin/sh
 2 # This is repro.sh -- use at your own risks
 3 rm -rf recipe > /dev/null
 4 mkdir recipe
 5 cd recipe
 6 git init
 7 mkdir lib
 8 echo "v1" > lib/main.rb
 9 git add lib/
10 git commit -m "initial version"
11 git checkout -b perf
12 echo "v2" >> lib/main.rb
13 git commit --all -m "perf improvements"
14 echo "v1" > lib/helper.rb
15 git add lib/helper.rb
16 git commit -m "new file"
17 git checkout master
18 git mv lib lib0
19 git commit -m "renamed"
20 git checkout perf
21 git merge master
22 find | grep -v .git

 1 $ . repro.sh 
 2 /home/francois/src/recipe
 3 Initialized empty Git repository in .git/
 4 Created initial commit a50ea59: initial version
 5  1 files changed, 1 insertions(+), 0 deletions(-)
 6  create mode 100644 lib/main.rb
 7 Switched to a new branch "perf"
 8 Created commit 73d3379: perf improvements
 9  1 files changed, 1 insertions(+), 0 deletions(-)
10 Created commit 01c0e0e: new file
11  1 files changed, 1 insertions(+), 0 deletions(-)
12  create mode 100644 lib/helper.rb
13 Switched to branch "master"
14 Created commit 66ac898: renamed
15  2 files changed, 1 insertions(+), 1 deletions(-)
16  delete mode 100644 lib/main.rb
17  create mode 100644 lib0/main.rb
18 Switched to branch "perf"
19 Merge made by recursive.
20  {lib => lib0}/main.rb |    0 
21  1 files changed, 0 insertions(+), 0 deletions(-)
22  rename {lib => lib0}/main.rb (100%)
23 .
24 ./lib
25 ./lib/helper.rb
26 ./lib0
27 ./lib0/main.rb

In prose, here’s what I did:

  • Initial development was in lib/main.rb
  • Then, I branched master to create a perf branch
  • On the perf branch, I added lib/helper.rb, and modified lib/main.rb
  • Back on master, I renamed lib/ to lib0/
  • Back on perf, I merged from master

What I expected to see is a move of lib/helper.rb and lib/main.rb to lib0/. Oh well, I don’t rename directories that often anyway. It’s more of a caveat than anything else.

Search

Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend

Links

Projects I work on

Projects I worked on