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
/home/francois/src/recipe
Initialized empty Git repository in .git/
Created initial commit a50ea59: initial version
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 lib/main.rb
Switched to a new branch “perf”
Created commit 73d3379: perf improvements
1 files changed, 1 insertions(+), 0 deletions(-)
Created commit 01c0e0e: new file
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 lib/helper.rb
Switched to branch “master”
Created commit 66ac898: renamed
2 files changed, 1 insertions(+), 1 deletions(-)
delete mode 100644 lib/main.rb
create mode 100644 lib0/main.rb
Switched to branch “perf”
Merge made by recursive.
{lib => lib0}/main.rb | 0
1 files changed, 0 insertions(+), 0 deletions(-)
rename {lib => lib0}/main.rb (100%)
.
./lib
./lib/helper.rb
./lib0
./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.
January 16th, 2008 at 12:44 PM
hey francois,
Glad to see you’re using git.
You forgot to add before your last commits
git add .
or
git commit -a
January 16th, 2008 at 02:00 PM
Marc, I did a “git mv”, and not a plain “mv”, so git is already aware of the change. Thanks for reading !
January 18th, 2008 at 06:42 PM
Git does not track file or directories. It only tracks the content of file (you cannot add an empty directory in git).
It this case, it could be argued that git did the right thing. Just because you moved the content of one file to another directory does not mean that someone who created a file in another branch wants their file also moved.
As you say, it’s a caveat to be aware of.
January 19th, 2008 at 10:01 AM
Sorry it this appears twice, but it seems my comment from yesterday did not get through.
Git does not track files or directories. It only tracks the content of files (you cannot add an empty directory in git).
It could be argued that what git did here is the correct behavior. Just because you moved the files from a directory does not mean a file created in a new branch should also move.
As you say, it is something to be aware of when using git.