My company uses SVN repository but I would like to use Git. At the moment I'm using git-svn, but when I move or rename a directory with a several of files in Git and "git svn dcommit" such change, in SVN repository this results into individual files moves:
Changed paths:
D /directory/file1
D /directory/file2
D /directory/file3
D /directory/file4
...
A /renamedDirectory
A /renamedDirectory/file1 (from /directory/file1:67918)
A /renamedDirectory/file2 (from /directory/file2:67918)
A /renamedDirectory/file3 (from /directory/file3:67918)
A /renamedDirectory/file4 (from /directory/file4:67918)
....
Instead I would expect to see something like that:
Changed paths:
D /directory
A /renamedDirectory (from /directory:67918)
i.e. full directory rename. Is there any way to solve the problem?
答案 0 :(得分:2)
When renaming (moving) directories in git, it's only the files that git moves, not the directory.
If I'm renaming a folder called pdfs
to pdfs2
$ git mv pdfs pdfs2
$ git status
renamed: pdfs/filea -> pdfs2/filea
renamed: pdfs/fileb -> pdfs2/fileb
So I think this how git works, and so git-svn works that way, too.
There isn't a way for git to say "I am 100% sure that this is a full directory move operation" and therefore translate this to SVN as a directory move. Git only knows/cares about the files.
Also: You'll notice that if you try commit an empty directory git will complain:
$ mkdir afolder
$ git add afolder && git commit -m "Added afolder"
On branch master
nothing to commit, working tree clean
This is again because git doesn't care about directories, just files.
答案 1 :(得分:1)
在文件移动和副本方面,SVN和Git之间存在重大差异:
Subversion保存在存储库中执行的每个复制操作的 copy-from 元数据。
Git不保留这种元数据,而是依赖于某些启发式方法来确定文件或目录是否被复制或移动。
不同的Git命令使用不同的重命名检测技术,例如, git log --stat -M
确实检测到目录重命名:
git log --stat -M
...
{directory => renamedDirectory}/file1
{directory => renamedDirectory}/file2
{directory => renamedDirectory}/file3
{directory => renamedDirectory}/file4
但是,在将Git提交发送到SVN存储库时,git-svn
不会尝试检测重命名的目录,因此,git-svn
生成的 copy-from 元数据不会反映目录重命名您期望的,它将重命名相应修订版中的单个文件。
我们在SubGit采用了不同的方法,它是git-svn
的替代方法:当用Git移动目录时:
$ git mv directory renamedDirectory
然后将此更改推送到启用了SubGit的Git存储库:
$ git commit -m 'Rename directory to renamedDirectory'
$ git push
SubGit确实将此更改转换为Subversion存储库中的目录重命名:
Changed paths:
D /directory
A /renamedDirectory (from /directory:123)
如果您发现在Subversion存储库中保留此类元数据很重要,您可以考虑尝试使用SubGit。这是一个quick start guide。