如何将git库移动到另一个目录并将该目录设置为git存储库? [英] How to move a git repository into another directory and make that directory a git repository?

查看:158
本文介绍了如何将git库移动到另一个目录并将该目录设置为git存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目录 gitrepo1 。这个目录是一个git仓库。




  • 我想将这个 gitrepo1 移动到另一个目录 newrepo

  • newrepo 应该是新的git存储库,不会丢失git历史记录,并且应该包含目录 gitrepo1
  • 现在应该是一个直接版本(在newrepo中),没有任何.git索引。即。它应该不再是一个独立的git存储库或子模块。




我该怎么做?

解决方案

这非常简单。 Git不关心它的目录名称是什么。它只关心里面的东西。所以你可以简单地做:

pre $ #将目录复制到已经存在的newrepo dir中(否则创建它)
$ cp -r gitrepo1 newrepo

从旧回购库中删除.git以删除所有历史记录和任何东西git
$ rm -rf gitrepo1 / .git

请注意,如果存储库很大且历史悠久,则副本相当昂贵。您可以轻松避免它:

 #移动目录改为
$ mv gitrepo1 newrepo

#复制最新版本
#或者:
$ mkdir gitrepo1; cp -r newrepo / * gitrepo1 /#不会复制.gitignore(和其他隐藏文件)

#或:
$ git clone --depth 1 newrepo gitrepo1; rm -rf gitrepo1 / .git

#或者(请看这里:http://stackoverflow.com/q/1209999/912144)
$ git archive --format = tar - remote =< repository URL> HEAD | tar xf -






创建 newrepo ,放置 gitrepo1 的目标可能在任何地方,甚至在 newrepo if内你想要它。它不会改变程序,只是你写的路径 gitrepo1 返回。


I have a directory gitrepo1. This directory is a git repository.

  • I want to move this gitrepo1 into another directory newrepo.

  • newrepo should be the new git repository with no loss of git history and should contain the directory gitrepo1

  • gitrepo1 should just be a directorty now (inside newrepo), without any .git index. ie. it should NO longer be an independent git repository or a submodule.

How can I do this?

解决方案

It's very simple. Git doesn't care about what's the name of its directory. It only cares what's inside. So you can simply do:

# copy the directory into newrepo dir that exists already (else create it)
$ cp -r gitrepo1 newrepo

# remove .git from old repo to delete all history and anything git from it
$ rm -rf gitrepo1/.git

Note that the copy is quite expensive if the repository is large and with a long history. You can avoid it easily too:

# move the directory instead
$ mv gitrepo1 newrepo

# make a copy of the latest version
# Either:
$ mkdir gitrepo1; cp -r newrepo/* gitrepo1/  # doesn't copy .gitignore (and other hidden files)

# Or:
$ git clone --depth 1 newrepo gitrepo1; rm -rf gitrepo1/.git

# Or (look further here: http://stackoverflow.com/q/1209999/912144)
$ git archive --format=tar --remote=<repository URL> HEAD | tar xf -


Once you create newrepo, the destination to put gitrepo1 could be anywhere, even inside newrepo if you want it. It doesn't change the procedure, just the path you are writing gitrepo1 back.

这篇关于如何将git库移动到另一个目录并将该目录设置为git存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆