xcode 将 git 存储库放在外部硬盘驱动器上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30041580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Place git repository on external hard drive
提问by Andriko13
I am using XCODE, and have recently decided to try using git (I am a lone app developer, so never really needed to use it). Because it used to take up a lot of storage space when I tried it previously, all of my current projects with git are stored on an external hard drive. I was wondering, however, whether it is possible to keep a development branch of a project on the hard drive of the mac, while keeping the main branch on the external hard drive. That way, I can merge the stable branches every few days to the external hard drive, and keep the development copy on my macbook to remove the need to carry my external hard drive with me everywhere I go. Is this possible? Any suggestions for a newbie on git?
我正在使用 XCODE,最近决定尝试使用 git(我是一个孤独的应用程序开发人员,所以从来没有真正需要使用它)。因为之前试过的时候会占用很大的存储空间,所以我现在用git的所有项目都存放在外置硬盘上。但是,我想知道是否可以在 mac 的硬盘驱动器上保留项目的开发分支,同时将主分支保留在外部硬盘驱动器上。这样,我可以每隔几天将稳定的分支合并到外部硬盘驱动器,并将开发副本保留在我的 macbook 上,从而无需随身携带外部硬盘驱动器。这可能吗?对 git 新手有什么建议吗?
回答by Gauthier
If the complete history of your project really is taking so much space (but reconsider and check twice if it really does), here could be a way to make this work:
如果您的项目的完整历史确实占用了太多空间(但如果确实如此,请重新考虑并检查两次),这里可能是一种使这项工作有效的方法:
First have your complete history in your remote
repo (external hard drive) in a branch main
(I would keep the default branch name master
, if I were you). Making it a bare repo is a good idea, to ease pushing later on. If you haven't done it already:
首先在你的remote
仓库(外部硬盘驱动器)的一个分支中拥有你的完整历史(如果我是你,main
我会保留默认的分支名称master
)。让它成为一个裸仓库是一个好主意,以便以后轻松推动。如果你还没有这样做:
$ cd /mnt/your/external/drive
$ git clone --bare /repo/where/you/currently/have/the/whole/history
Then when you want to start a new development phase, take a shallow clone from remote
to local
(your laptop's hard drive)
然后当你想开始一个新的开发阶段时,从remote
到local
(你的笔记本电脑的硬盘)进行一个浅克隆
$ cd $HOME/
$ git clone --depth 10 /mnt/you/external/drive/repo.git
This clones the repository, but only the last 10 commits are in history. That way if your history really is enormous, you'd save space (again, look twice if space taken by history really is a problem).
这会克隆存储库,但只有最后 10 次提交在历史记录中。这样,如果您的历史记录真的很庞大,您就可以节省空间(如果历史记录占用的空间确实有问题,请再次查看)。
Create a work branch as you normally would, work in that branch, merge to main
, push to remote
:
像往常一样创建一个工作分支,在该分支中工作,合并到main
,推送到remote
:
$ git checkout -b super_feature # use good branch names, not "dev"
... work, commit, work, commit, work, commit, ... time to merge.
$ git checkout main
$ git merge super_feature # I usually add --no-ff
$ git push origin main
And there you go. You worked on your local shallowclone of your remote
, with limited history.
你去吧。你在你的本地浅层克隆上工作remote
,历史有限。
After a while, your shallow clone will have more and more history. If history space becomes an issue again (but... you know), just ditch the shallow clone and make a new fresh one from the remote
.
一段时间后,您的浅层克隆将拥有越来越多的历史。如果历史空间再次成为问题(但是......你知道),只需放弃浅克隆并从remote
.
回答by Sam Varshavchik
git doesn't care where a repository lives.
git 不关心存储库的位置。
You can create a repository on one hard drive, clone it to another hard drive, and push/pull branches between both repositories.
您可以在一个硬盘驱动器上创建存储库,将其克隆到另一个硬盘驱动器,并在两个存储库之间推送/拉取分支。