简体   繁体   English

我可以安全地将本地Git存储库移动到我的硬盘中的其他位置吗?

[英]Can I move a local Git repository to elsewhere within my hard drive safely?

I started using Git/SourceTree/Bitbucket lately. 我最近开始使用Git / SourceTree / Bitbucket。 Can I move a local Git repository to elsewhere within my hard drive safely? 我可以安全地将本地Git存储库移动到我的硬盘中的其他位置吗?

Because some of the large files are ignored by Git, I cannot really pull the repository from a remote repository to get the exact copy of all the files. 因为Git忽略了一些大文件,所以我无法从远程存储库中获取存储库以获取所有文件的精确副本。

If I simply move or copy the home directory that contains .git to elsewhere, would it cause any mess to Git? 如果我只是将包含.git的主目录移动或复制到其他地方,是否会导致Git混乱? If the absolute paths matters to Git, I guess it would, but I'm not sure. 如果绝对路径对Git很重要,我猜它会,但我不确定。

No, moving or copying the .git/ folder will not cause problems for git; 不,移动或复制.git/文件夹不会导致git出现问题; git is not connected to your repo in any way, and git doesn't care about absolute paths, only relative paths inside the project folder. git没有以任何方式连接到你的repo,git不关心绝对路径,只关心项目文件夹中的相对路径。

Git is just an executable on your machine. Git只是您计算机上的可执行文件。 It can run anywhere, as long as it's in your path. 它可以在任何地方运行,只要它在你的路径中。 I often drag my various .git/ folders to different places, or even onto my thumb drive (usually I drag the whole repository folder, but I've also just brought the .git/ folder by itself). 我经常将各种.git/文件夹拖到不同的地方,甚至拖到我的拇指驱动器上(通常我拖动整个存储库文件夹,但我也只是自带了.git/文件夹)。 The nice thing about git is that literally everything about your repo is in that folder. 关于git的好处是,关于你的repo的所有内容都在该文件夹中。 You don't even need to bring the working tree files with you. 您甚至不需要随身携带工作树文件。 If you drop the .git/ folder - or a copy - into another folder, you can git checkout master in that folder, and git will rebuild the working tree there. 如果你将.git/文件夹 - 或副本 - 放到另一个文件夹中,你可以在该文件夹中git checkout master ,git将在那里重建工作树。

This is the great thing about everything being data. 关于数据的一切都是件好事。 Git is not attached to your repository at all. Git根本没有附加到您的存储库。 You just call git to do work on your repository to create or change the data that exists there, and then it lets go entirely again. 你只需要调用git就可以在你的存储库上工作来创建或更改那里存在的数据,然后再让它完全重新开始。

Keep in mind you can clone your own local repo: 请记住,您可以克隆自己的本地仓库:

$ git clone oldrepo newrepo

Git will copy the oldrepo to the newrepo ( newrepo can be a path to anywhere on your local filesystem), creating that folder in the process. Git会将oldrepo复制到newreponewrepo可以是本地文件系统中任意位置的路径),在此过程中创建该文件夹。 Also, newrepo will have a remote added automatically - origin - that points back to oldrepo , so you could do work in oldrepo , and fetch it in over in the newrepo folder. 此外, newrepo将自动添加一个遥控器 - origin - 指向oldrepo ,因此你可以在oldrepo工作,并在newrepo文件夹中获取它。 If you don't want that remote (it's harmless) you can just do git remote rm origin in the new repo. 如果您不想要那个遥控器(它是无害的),您可以在新的仓库中执行git remote rm origin If you want to hook the copied repo back up to a server online, just do git remote add origin <url> . 如果您想将复制的repo挂钩到服务器在线,只需执行git remote add origin <url> If you're not sure what the URL was, do a git remote -v in the oldrepo and copy the URL from there. 如果您不确定URL是什么,请在oldrepo执行git remote -v并从那里复制URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM