tags:

views:

255

answers:

3

The only distributed revision control system I've used on my projects is bazaar. I don't know much about git and mercurial except how to do checkouts. The reason I like bazaar is the automv plugin. It detects when I've moved/deleted files manualy (from command line/ide etc.) which I tend to do alot when I'm in a hurry. But bazaar is really slow and I'm thinking of moving to git. Does git have something similar to this functionality?

+8  A: 

The way Git works in the move/rename situation is quite different. Git tracks only content, so it knows that file X had SHA1 hash abc123... at one commit, and file Y happened to have the same hash abc123... at the next commit. So the Git tools, when viewing history or whatever, conclude that file X must have been renamed to filename Y at that point.

In this way, Git reconstructs the actions taken to move from one commit to the next, without having to have that knowledge at commit time. It can event detect situations where you rename a file and change something within the file (of course it doesn't do this by comparing SHA1 hashes, but by doing a text compare between files that were changed in a commit).

Greg Hewgill
Presumably it's also smart enough to guess that something was a move if there are minor changes (e.g. the namespace declaration in a C# file)? Would check for myself, but can't on this laptop...
Jon Skeet
@Jon Skeet: Yes, just updated my answer to reflect that.
Greg Hewgill
Yeah, that works beautifully with git. I'm totally annoyed by SVN because it cannot recognize these things automatically.
David Schmitt
What happens if git doesn't find file X on the next commit (I've deleted it)? SVN will really make a fuss in this case, which is why I only use SVN with a gun to my head.
Vasil
The file is shown as deleted when you run "git status", to commit the deletion you have to use "git rm". Keep in mind that svn tries to be smart and commit everything, whereas git has the index and you have to tell it what to commit. Deletion is not a special case in git, whereas it is in svn.
rq
@Greg Hewgill: To be more exact git does heuristic contents and filename similarity based rename detection (when asked to; you can configure to have it always turned on). Relyong on exact the same content (therefore the same SHA1 idenifier of a contents of a file) is a special case.
Jakub Narębski
+2  A: 

You might be looking for git add --all:

Update files that git already knows about (same as --update) and add all untracked files that are not ignored by .gitignore mechanism.

(Emphasis mine.)

Jörg W Mittag
+1  A: 

Just for your information only bazaar knows moves. SVN, Git, hg only know copy with version and delete. I think that a different. But as mentioned before git handles the automv very well (as far as I heard), only be so clever to commit very quickly after move. I heard egit makes an autocommit after you rename a class.

niels