Moving a git repo to another server

孤街醉人 提交于 2019-12-22 10:02:33

问题


I have a git clone/repo on a development server, but I am now moving to another one. I don't want to commit all my local branches and changes to the main repository, so how can I make an exact copy of everything on oldserver to newserver?

I tried oldserver:~$ scp -rp project newserver:~/project

but then I just get loads and loads of "typechange" errors when trying to do anything on newserver.

Someone said something about x-modes, but how can I preserve that when moving files between servers?


回答1:


If you want a git solution, you could try

git clone --mirror <oldurl> <newurl>

though this is only for bare repositories.

If this is a non-bare repo, you could also do the normal clone, followed by something like this:

git fetch origin
git branch -r | grep '^ *origin/[^ ]*$' |
    while read rb; do git branch --no-track ${rb#*/} $rb; done
git remote rm origin

The middle step can of course be done in 5000 different ways, but that's one! (note that the continuation line \ isn't necessary after the pipe in bash - it knows it needs more input)

Finally, I'd suggest using rsync instead of scp (probably with -avz options?) if you want to directly copy. (What exactly are these typechange errors?)




回答2:


I've actually done this, and all I did was tar the repo up first and scp it over. I would think that scp -rp would work as well.

"Typechange" would normally refer to things like a symlink becoming a file or vice-versa. Are the two servers running the same OS?




回答3:


You may also want to try the simple dumb solution -- don't worry about how the typechanges got there, but let git fix them with a reset command:

git reset --hard HEAD

That only makes sense if (1) the problems all pertain to the checked-out files (and not the repository structure itself) and (2) you haven't made any changes on newserver which you need to preserve.

Given those caveats, it worked for me when I found myself with the same problem, and it doesn't require you to think about git's internals or how well your file-transfer process is preserving attributes.



来源:https://stackoverflow.com/questions/1631346/moving-a-git-repo-to-another-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!