我有一个目录gitrepo1。该目录是一个 git 存储库。
我想将此gitrepo1移动到另一个目录newrepo。
目录newrepo应该是没有丢失 git 历史记录的新 git 存储库,并且应该包含目录gitrepo1。
目录gitrepo1现在应该只是一个目录(在newrepo内),没有任何
.git索引,即它不应该不再是一个独立的 git 存储库或子模块。
我怎样才能做到这一点?
我有一个目录gitrepo1。该目录是一个 git 存储库。
我想将此gitrepo1移动到另一个目录newrepo。
目录newrepo应该是没有丢失 git 历史记录的新 git 存储库,并且应该包含目录gitrepo1。
目录gitrepo1现在应该只是一个目录(在newrepo内),没有任何.git索引,即它不应该不再是一个独立的 git 存储库或子模块。
我怎样才能做到这一点?
这很简单。Git 不关心其目录的名称。它只关心里面的东西。所以你可以简单地做:
# 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
请注意,如果存储库很大且历史悠久,则副本非常昂贵。您也可以轻松避免它:
# 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 -
一旦你创建newrepo,放置的目的地gitrepo1可以是任何地方,即使newrepo你想要它在里面。它不会改变程序,只会改变你写gitrepo1回的路径。
它甚至比这更简单。刚刚这样做(在 Windows 上,但它应该在其他操作系统上工作):
Git 只是看到你添加了一个目录并重命名了一堆文件。没什么大不了的。
要做到这一点而不会感到头疼:
git status,比如说分支“开发”。git clone是存储库中的项目。git checkout development.rsyncrsync -azv --exclude '.git' gitrepo1 newrepo/gitrepo1rsync您可以从上次中断的地方继续:您的旧分支、未分阶段的更改等。
我不是专家,但我将 .git 文件夹复制到一个新文件夹,然后调用:git reset --hard
将 git 存储库移动到另一个目录并使用镜像方法使该目录成为 git 存储库的简单方法
git clone --mirror git@example.com/mirror-repository.git
cd mirror-repository.git
使用以下命令将更改推送到新存储库
git push --mirror git@example.com/new-mirror.git
这将获取镜像存储库中可用的所有分支和标签,并将它们复制到新位置。
不要在没有被 --mirror 克隆的存储库中使用 git push --mirror 。它将用您的本地引用(和您的本地分支)覆盖远程存储库。 git clone --mirror 优于 git clone --bare 因为前者还克隆 git 注释和其他一些属性。