Rename Processing: svn vs. git vs. mercurial

How does each of these VCS handlers rename?

I found a lot of conflicting information that git tracks LOC (lines of code) instead of files, so renaming doesn't matter to him.

+45
git version-control svn mercurial rename
Oct 08 '09 at 12:55
source share
6 answers
  • Git does not track renames at all, but uses heuristics to re-detect them during merge, etc.
  • It is renamed Mercurial tracks (the original version and source file are recorded) and uses this information during mergers. Therefore, you need to explicitly tell hg to rename with hg mv or use hg addremove --similarity for automatic detection. There was talk of adding heuristics during the merge too.
  • Svn keeps track of renaming, but I don’t know how good it is with them during mergers (I never tested this).
+41
Oct 08 '09 at 13:21
source share

Git

Git differs in that it does not rename the tracking , which means that it does not need to report renames using SCM commands to perform renaming (or run an autodetection script to mark renames before committing) and does not save this information in the repository, but she renames the discovery . This means that it finds renames using a heuristic similarity algorithm based on the file name and file contents, both during merge and for diff when requested through the -M option (or configured using the diff.renames config option).

The advantages of this method are as follows:

  • renames do not have to be marked (or detected) explicitly: renaming can occur from a patch or vie filemanager or GUI can be performed
  • the similarity detection algorithm can be improved and was not frozen during the commit, as in the case of detection of renaming for marking before commit and storing this information in the repository; it is also easier to deal with rename detection errors if they are not frozen in history.
  • Git ophilosophy follows, which is important content; see how Git wame (and its graphical interfaces like “git gui wame”) can track the movement of code blocks across file boundaries, which is more common than renaming files.
  • the same mechanism is responsible for handling renaming during mergers; the use of renaming means that this can be done for 3 commits, which are ultimately based on a merge, and there is no need to carefully monitor the history, noting each renaming - or the uncommon concept of the canonical file name.

Note that pathspec filtering does not work with rename detection; if you want to keep track of file history through renaming, use " git log --follow <filename> "

+22
09 Oct '09 at 9:06
source share

On practice:

Git automatically detects renames. (By the way, I heard allegations that git can detect when you move a function from one file to another. My initial tests seem to indicate that this is not the case.)

With Mercurial, you must explicitly specify rename names, either using the hg mv , or the --similarity option of the hg addremove , TortoiseHg "renaming assumption", or some tools, for example. VisualHg will mark the rename for you. If you want to use git approach with Mercurial, I wrote extension

+10
Jun 26 '10 at 7:25
source share

You heard the truth, sort of.

Git works with the contents of the files, not the files themselves, so renaming is technically pointless for him. In git, renaming looks like file A disappeared, and file B appeared with the same contents as A. But git is actually very well-understood when the file was really renamed.

Try it: rename the file, then run 'git rm oldname' and 'git add newname' to tell git to make changes, then run 'git status' to see what git thinks it does - you will see that it tells you that the file has been renamed. However, I’m not sure if this means anything else. Look at the commit with 'git show' and you will not see any mention of renaming, just a bunch of lines removed from one path and added to another.

Alternatively, you can also use the git mv 'command to rename the file. It does not change how git sees the operation, it just efficiently executes “mv oldname newname”, “git rm oldname” and “git add new name” in one step.

For a Mercurial review, see tonfa answer .

SVN, on the other hand, cannot detect renames, but must report them using the svn mv command. However, when said, it tracks the rename as "first class," so when you look at the list of changes, you will see that the change was a rename.

I would not suggest choosing SVN over git or mercury based on this function. Significantly large and important differences between tools. I would first decide if you want a distributed version control system (git or mercurial) or a centralized version control system (svn).

+6
Oct 08 '09 at 13:20
source share

One more thing about git that hasn't been mentioned yet, besides using heuristics to determine if renaming has happened:

If a file or even a complete directory tree is renamed, copied or moved, and nothing under it changes in any way, then the file or tree is actually stored as the same object inside the repository and does not take any additional space.

If you change it, it will be saved as a new object, as usual.

I'm not sure about hg and svn, but I suspect that their changes to the change lists mean that they behave differently in this scenario. This really does not affect usage, except that it may result in you being unable to move or copy huge trees inside your repository.

+3
Oct 10 '09 at 8:10
source share

git tracks content, not files. im not sure about mercurial, but svn should be explicitly said about renaming

0
Oct 08 '09 at 13:05
source share



All Articles