开发者

Using git to sync existing file collection?

开发者 https://www.devze.com 2023-02-02 11:29 出处:网络
I\'ve got a collection of files that formerly lived in a Subversion repo; on my new server I\'ve imported them into a git repo so I could start getting more experience with that.

I've got a collection of files that formerly lived in a Subversion repo; on my new server I've imported them into a git repo so I could start getting more experience with that.

On several other machines, I've got m开发者_如何学编程ostly up-to-date copies of the existing svn repo files.

  • Is there any way to sync to the new git repo, but use these existing files so I don't have to re-transfer all of the data?

  • Is git smart enough that if I do a fetch? or checkout? that it'll notice the files are identical and not re-transfer them?


Git does not operate on files, but with snapshots. And the protocol git uses to decide what needs downloading works on whole commits at once. If you initialize two repos with slightly different files (or even identical files, but they have no commits in common), then it will need to download all of the objects when you fetch, even though there will be many duplicated trees and blobs that it will clean up at a later date.

You can try this out by initializing two repositories with the same files, and watching the disk space as you run these commands:

du -sh .git
git remote add origin ../other
git fetch
du -sh .git
git prune
du -sh .git

The fetch step will copy all of the data, and the prune step will remove all of the duplicated objects.

If you want to be able to fetch efficiently, you will at some point have to prove to git that you have some commits in common, since push/fetch protocol communicates by using whole commits (and really with branch names). The easiest way is just to clone your git repo somewhere, and then you can base work off of that and synchronize your various changes efficiently.

However, if you have access to the same SVN snapshot on multiple servers, you can create identical commits if you commit trees which are 100% identical and use the same information for GIT_AUTHOR_NAME, GIT_AUTHOR_DATE, and so on.


Maybe git-svn is what you're looking for?

It allows for bidirectional operation between a Subversion repository and a Git repository.

I've never used it, but I know developers who do. It allows them to fetch files from Subversion, use Git as their own private version control system where they can save changes without having to send them to Subversion. Then, once they're done, they push their changes back to Subversion.

0

精彩评论

暂无评论...
验证码 换一张
取 消